A cikin al'ummar yau inda bayanai suka zama ruwan dare, mu'amala da takaddun HTML ba banda bane. Kowane shafin yanar gizon sararin samaniya an gina shi akan HTML, ฦirฦirar ragamar labyrinthine na abubuwa da tags. Makullin kewayawa ta wannan ragar cikin tsari da tsari shine ta hanyar amfani da na'urar tambayaSelectorAll Hanyar a JavaScript ko, a cikin yanayinmu a nan, TypeScript. A yau, za mu zurfafa zurfafa cikin yin amfani da damar tambayarSelectorAll azaman HTMLElement a cikin TypeScript.
TypeScript, babban juzu'i na JavaScript, ana iya yiwa alama alama azaman tsattsauran ra'ayi ga masu haษakawa da ke aiki tare da JS. Yana haษaka JavaScript ta hanyar ฦara nau'ikan da kawo cikin tsarin Shirye-shiryen Abubuwan da ke Kan Abu. The tambayaSelectorAll Hanyar kayan aiki ne mai ฦarfi a cikin akwatin kayan aiki na TypeScript da kowane mai haษaka gidan yanar gizo.
let elements: NodeListOf<HTMLElement> = document.querySelectorAll(".class");
Zurfafa nutsewa cikin tambayaSelectorAll
Lambar lambar da ke sama, kodayake tana da kyau a gaba, tana da yadudduka a ciki. The tambayaSelectorAll Hanyar a cikin TypeScript yana aiki daidai da hanyar JavaScript na gargajiya; yana dawo da jerin abubuwan da ke cikin takaddun da suka dace da ฦungiyar masu zaษin da aka ฦayyade. Nau'in annotation na NodeListOf yana tabbatar da cewa muna hulษa da HTMLElements.
A cikin sauฦi, yana ba da damar zaษin kowane nau'in HTML da ke kan shafin yanar gizon da ya dace da ฦayyadaddun yanayin. Misali, yana iya taimakawa wajen zaษar abubuwa ta aji, id, tag, har ma da hadaddun haษaษษiya.
Dakunan karatu masu alaฦa da Ayyuka
Duk da yake tambayaSelectorAll yana da ฦarfi sosai, yana da kyau a bincika manufar dangane da wasu ษakunan karatu, ayyuka, ko hanyoyin:
- The samunElementById Hanyar tana ba da damar shiga kai tsaye zuwa kashi ta musamman id.
- samunElementsByClass Name da kuma samunElementsByTagName hanyoyin tattara HTML Tarin abubuwa masu rai.
- A cikin daular jQuery, da $('.class') sanannen zaษi ne don ษauko abubuwa ta aji.
Amfani da querySelectorAll tare da TypeScript
Hakikanin ikon tambayaSelectorAll yana haskakawa yadda ya kamata lokacin amfani da shi a cikin daular TypeScript. Godiya ga tsayayyen nau'ikan TypeScript, muna da tabbacin cewa abubuwan da aka dawo dasu za su zama HTMLElements, yin aiki na gaba akan waษannan abubuwan iska. Wannan yana rage girman kurakuran lokacin aiki kuma yana sauฦaฦe cikawa ta atomatik a cikin masu gyara rubutu masu tallafi.
A cikin tattara wannan faษuwar cikin yanayin querySelectorAll, HTMLElement da TypeScript, a bayyane yake cewa ba za a iya raina ฦarfin irin waษannan fasahohin ba. Ta hanyar haษa zaษi na hankali tare da samun damar shirye-shirye zuwa abubuwa akan shafin yanar gizon, mutum na iya ฦirฦirar ฦwarewar mu'amala ta gaske da kuzari. Tushen ilimin waษannan iyawar shine, don haka, kayan aiki mai ฦarfi a cikin bel na kowane mai haษaka gidan yanar gizo na zamani.