如何从jQuery获取选项值

时间:2018-10-22 14:26:14

标签: javascript php jquery codeigniter

我想从列表中获取数据。每当我尝试选择任何值

(batch_size, num_time_steps, ...)

当我发出警报时如何获取数据拨号代码。

<ul class="country-list hide" id="country-listbox" aria-expanded="false" role="listbox" aria-activedescendant="iti-item-al"><li class="country preferred" id="iti-item-fr" role="option" data-dial-code="33" data-country-code="fr" aria-selected="false"><div class="flag-box"><div class="iti-flag fr"></div></div><span class="country-name">France</span><span class="dial-code">+33</span></li><li class="divider" role="separator" aria-disabled="true"></li><li class="country standard" id="iti-item-af" role="option" data-dial-code="93" data-country-code="af"><div class="flag-box"><div class="iti-flag af"></div></div><span class="country-name">Afghanistan (‫افغانستان‬‎)</span><span class="dial-code">+93</span></li><li class="country standard highlight active" id="iti-item-al" role="option" data-dial-code="355" data-country-code="al" aria-selected="true"><div class="flag-box"><div class="iti-flag al"></div></div><span class="country-name">Albania (Shqipëri)</span><span class="dial-code">+355</span></li><li class="country standard" id="iti-item-dz" role="option" data-dial-code="213" data-country-code="dz"><div class="flag-box"><div class="iti-flag dz"></div></div><span class="country-name">Algeria (‫الجزائر‬‎)</span><span class="dial-code">+213</span></li><li class="country standard" id="iti-item-as" role="option" data-dial-code="1684" data-country-code="as"><div class="flag-box"><div class="iti-flag as"></div></div><span class="country-name">American Samoa</span><span class="dial-code">+1684</span></li><li class="country standard" id="iti-item-ad" role="option" data-dial-code="376" data-country-code="ad"><div class="flag-box"><div class="iti-flag ad"></div></div><span class="country-name">Andorra</span><span class="dial-code">+376</span></li><li class="country standard" id="iti-item-ao" role="option" data-dial-code="244" data-country-code="ao"><div class="flag-box"><div class="iti-flag ao"></div></div><span class="country-name">Angola</span><span class="dial-code">+244</span></li><li class="country standard" id="iti-item-ai" role="option" data-dial-code="1264" data-country-code="ai"><div class="flag-box"><div class="iti-flag ai"></div></div><span class="country-name">Anguilla</span><span class="dial-code">+1264</span></li><li class="country standard" id="iti-item-ag" role="option" data-dial-code="1268" data-country-code="ag"><div class="flag-box"><div class="iti-flag ag"></div></div><span class="country-name">Antigua and Barbuda</span><span class="dial-code">+1268</span></li><li class="country standard" id="iti-item-ar" role="option" data-dial-code="54" data-country-code="ar"><div class="flag-box"><div class="iti-flag ar"></div></div><span class="country-name">Argentina</span><span class="dial-code">+54</span></li><li class="country standard" id="iti-item-am" role="option" data-dial-code="374" data-country-code="am"><div class="flag-box"><div class="iti-flag am"></div></div><span class="country-name">Armenia (Հայաստան)</span><span class="dial-code">+374</span></li><li class="country standard" id="iti-item-aw" role="option" data-dial-code="297" data-country-code="aw"><div class="flag-box"><div class="iti-flag aw"></div></div><span class="country-name">Aruba</span><span class="dial-code">+297</span></li><li class="country standard" id="iti-item-au" role="option" data-dial-code="61" data-country-code="au"><div class="flag-box"><div class="iti-flag au"></div></div><span class="country-name">Australia</span><span class="dial-code">+61</span></li><li class="country standard" id="iti-item-at" role="option" data-dial-code="43" data-country-code="at"><div class="flag-box"><div class="iti-flag at"></div></div><span class="country-name">Austria (Österreich)</span><span class="dial-code">+43</span></li><li class="country standard" id="iti-item-az" role="option" data-dial-code="994" data-country-code="az"><div class="flag-box"><div class="iti-flag az"></div></div><span class="country-name">Azerbaijan (Azərbaycan)</span><span class="dial-code">+994</span></li><li class="country standard" id="iti-item-bs" role="option" data-dial-code="1242" data-country-code="bs"><div class="flag-box"><div class="iti-flag bs"></div></div><span class="country-name">Bahamas</span><span class="dial-code">+1242</span></li><li class="country standard" id="iti-item-bh" role="option" data-dial-code="973" data-country-code="bh"><div class="flag-box"><div class="iti-flag bh"></div></div><span class="country-name">Bahrain (‫البحرين‬‎)</span><span class="dial-code">+973</span></li><li class="country standard" id="iti-item-bd" role="option" data-dial-code="880" data-country-code="bd"><div class="flag-box"><div class="iti-flag bd"></div></div><span class="country-name">Bangladesh (বাংলাদেশ)</span><span class="dial-code">+880</span></li><li class="country standard" id="iti-item-bb" role="option" data-dial-code="1246" data-country-code="bb"><div class="flag-box"><div class="iti-flag bb"></div></div><span class="country-name">Barbados</span><span class="dial-code">+1246</span></li><li class="country standard" id="iti-item-by" role="option" data-dial-code="375" data-country-code="by"><div class="flag-box"><div class="iti-flag by"></div></div><span class="country-name">Belarus (Беларусь)</span><span class="dial-code">+375</span></li><li class="country standard" id="iti-item-be" role="option" data-dial-code="32" data-country-code="be"><div class="flag-box"><div class="iti-flag be"></div></div><span class="country-name">Belgium (België)</span><span class="dial-code">+32</span></li><li class="country standard" id="iti-item-bz" role="option" data-dial-code="501" data-country-code="bz"><div class="flag-box"><div class="iti-flag bz"></div></div><span class="country-name">Belize</span><span class="dial-code">+501</span></li><li class="country standard" id="iti-item-bj" role="option" data-dial-code="229" data-country-code="bj"><div class="flag-box"><div class="iti-flag bj"></div></div><span class="country-name">Benin (Bénin)</span><span class="dial-code">+229</span></li><li class="country standard" id="iti-item-bm" role="option" data-dial-code="1441" data-country-code="bm"><div class="flag-box"><div class="iti-flag bm"></div></div><span class="country-name">Bermuda</span><span class="dial-code">+1441</span></li><li class="country standard" id="iti-item-bt" role="option" data-dial-code="975" data-country-code="bt"><div class="flag-box"><div class="iti-flag bt"></div></div><span class="country-name">Bhutan (འབྲུག)</span><span class="dial-code">+975</span></li><li class="country standard" id="iti-item-eg" role="option" data-dial-code="20" data-country-code="eg"><div class="flag-box"><div class="iti-flag eg"></div></div><span class="country-name">Egypt (‫مصر‬‎)</span><span class="dial-code">+20</span></li><li class="country standard" id="iti-item-sv" role="option" data-dial-code="503" data-country-code="sv"><div class="flag-box"><div class="iti-flag sv"></div></div><span class="country-name">El Salvador</span><span class="dial-code">+503</span></li><li class="country standard" id="iti-item-gq" role="option" data-dial-code="240" data-country-code="gq"><div class="flag-box"><div class="iti-flag gq"></div></div><span class="country-name">Equatorial Guinea (Guinea Ecuatorial)</span><span class="dial-code">+240</span></li><li class="country standard" id="iti-item-er" role="option" data-dial-code="291" data-country-code="er"><div class="flag-box"><div class="iti-flag er"></div></div><span class="country-name">Eritrea</span><span class="dial-code">+291</span></li><li class="country standard" id="iti-item-ee" role="option" data-dial-code="372" data-country-code="ee"><div class="flag-box"><div class="iti-flag ee"></div></div><span class="country-name">Estonia (Eesti)</span><span class="dial-code">+372</span></li><li class="country standard" id="iti-item-et" role="option" data-dial-code="251" data-country-code="et"><div class="flag-box"><div class="iti-flag et"></div></div><span class="country-name">Ethiopia</span><span class="dial-code">+251</span></li><li class="country standard" id="iti-item-fk" role="option" data-dial-code="500" data-country-code="fk"><div class="flag-box"><div class="iti-flag fk"></div></div><span class="country-name">Falkland Islands (Islas Malvinas)</span><span class="dial-code">+500</span></li><li class="country standard" id="iti-item-fo" role="option" data-dial-code="298" data-country-code="fo"><div class="flag-box"><div class="iti-flag fo"></div></div><span class="country-name">Faroe Islands (Føroyar)</span><span class="dial-code">+298</span></li><li class="country standard" id="iti-item-fj" role="option" data-dial-code="679" data-country-code="fj"><div class="flag-box"><div class="iti-flag fj"></div></div><span class="country-name">Fiji</span><span class="dial-code">+679</span></li><li class="country standard" id="iti-item-fi" role="option" data-dial-code="358" data-country-code="fi"><div class="flag-box"><div class="iti-flag fi"></div></div><span class="country-name">Finland (Suomi)</span><span class="dial-code">+358</span></li><li class="country standard" id="iti-item-fr" role="option" data-dial-code="33" data-country-code="fr"><div class="flag-box"><div class="iti-flag fr"></div></div><span class="country-name">France</span><span class="dial-code">+33</span></li><li class="country standard" id="iti-item-gf" role="option" data-dial-code="594" data-country-code="gf"><div class="flag-box"><div class="iti-flag gf"></div></div><span class="country-name">French Guiana (Guyane française)</span><span class="dial-code">+594</span></li><li class="country standard" id="iti-item-pf" role="option" data-dial-code="689" data-country-code="pf"><div class="flag-box"><div class="iti-flag pf"></div></div><span class="country-name">French Polynesia (Polynésie française)</span><span class="dial-code">+689</span></li><li class="country standard" id="iti-item-ga" role="option" data-dial-code="241" data-country-code="ga"><div class="flag-box"><div class="iti-flag ga"></div></div><span class="country-name">Gabon</span><span class="dial-code">+241</span></li><li class="country standard" id="iti-item-ro" role="option" data-dial-code="40" data-country-code="ro"><div class="flag-box"><div class="iti-flag ro"></div></div><span class="country-name">Romania (România)</span><span class="dial-code">+40</span></li><li class="country standard" id="iti-item-ru" role="option" data-dial-code="7" data-country-code="ru"><div class="flag-box"><div class="iti-flag ru"></div></div><span class="country-name">Russia (Россия)</span><span class="dial-code">+7</span></li><li class="country standard" id="iti-item-rw" role="option" data-dial-code="250" data-country-code="rw"><div class="flag-box"><div class="iti-flag rw"></div></div><span class="country-name">Rwanda</span><span class="dial-code">+250</span></li><li class="country standard" id="iti-item-bl" role="option" data-dial-code="590" data-country-code="bl"><div class="flag-box"><div class="iti-flag bl"></div></div><span class="country-name">Saint Barthélemy</span><span class="dial-code">+590</span></li><li class="country standard" id="iti-item-sh" role="option" data-dial-code="290" data-country-code="sh"><div class="flag-box"><div class="iti-flag sh"></div></div><span class="country-name">Saint Helena</span><span class="dial-code">+290</span></li><li class="country standard" id="iti-item-kn" role="option" data-dial-code="1869" data-country-code="kn"><div class="flag-box"><div class="iti-flag kn"></div></div><span class="country-name">Saint Kitts and Nevis</span><span class="dial-code">+1869</span></li><li class="country standard" id="iti-item-lc" role="option" data-dial-code="1758" data-country-code="lc"><div class="flag-box"><div class="iti-flag lc"></div></div><span class="country-name">Saint Lucia</span><span class="dial-code">+1758</span></li><li class="country standard" id="iti-item-mf" role="option" data-dial-code="590" data-country-code="mf"><div class="flag-box"><div class="iti-flag mf"></div></div><span class="country-name">Saint Martin (Saint-Martin (partie française))</span><span class="dial-code">+590</span></li><li class="country standard" id="iti-item-pm" role="option" data-dial-code="508" data-country-code="pm"><div class="flag-box"><div class="iti-flag pm"></div></div><span class="country-name">Saint Pierre and Miquelon (Saint-Pierre-et-Miquelon)</span><span class="dial-code">+508</span></li><li class="country standard" id="iti-item-vc" role="option" data-dial-code="1784" data-country-code="vc"><div class="flag-box"><div class="iti-flag vc"></div></div><span class="country-name">Saint Vincent and the Grenadines</span><span class="dial-code">+1784</span></li><li class="country standard" id="iti-item-ws" role="option" data-dial-code="685" data-country-code="ws"><div class="flag-box"><div class="iti-flag ws"></div></div><span class="country-name">Samoa</span><span class="dial-code">+685</span></li><li class="country standard" id="iti-item-sm" role="option" data-dial-code="378" data-country-code="sm"><div class="flag-box"><div class="iti-flag sm"></div></div><span class="country-name">San Marino</span><span class="dial-code">+378</span></li><li class="country standard" id="iti-item-st" role="option" data-dial-code="239" data-country-code="st"><div class="flag-box"><div class="iti-flag st"></div></div><span class="country-name">São Tomé and Príncipe (São Tomé e Príncipe)</span><span class="dial-code">+239</span></li><li class="country standard" id="iti-item-sa" role="option" data-dial-code="966" data-country-code="sa"><div class="flag-box"><div class="iti-flag sa"></div></div><span class="country-name">Saudi Arabia (‫المملكة العربية السعودية‬‎)</span><span class="dial-code">+966</span></li><li class="country standard" id="iti-item-sn" role="option" data-dial-code="221" data-country-code="sn"><div class="flag-box"><div class="iti-flag sn"></div></div><span class="country-name">Senegal (Sénégal)</span><span class="dial-code">+221</span></li><li class="country standard" id="iti-item-rs" role="option" data-dial-code="381" data-country-code="rs"><div class="flag-box"><div class="iti-flag rs"></div></div><span class="country-name">Serbia (Србија)</span><span class="dial-code">+381</span></li><li class="country standard" id="iti-item-sc" role="option" data-dial-code="248" data-country-code="sc"><div class="flag-box"><div class="iti-flag sc"></div></div><span class="country-name">Seychelles</span><span class="dial-code">+248</span></li><li class="country standard" id="iti-item-sl" role="option" data-dial-code="232" data-country-code="sl"><div class="flag-box"><div class="iti-flag sl"></div></div><span class="country-name">Sierra Leone</span><span class="dial-code">+232</span></li><li class="country standard" id="iti-item-sg" role="option" data-dial-code="65" data-country-code="sg"><div class="flag-box"><div class="iti-flag sg"></div></div><span class="country-name">Singapore</span><span class="dial-code">+65</span></li><li class="country standard" id="iti-item-sx" role="option" data-dial-code="1721" data-country-code="sx"><div class="flag-box"><div class="iti-flag sx"></div></div><span class="country-name">Sint Maarten</span><span class="dial-code">+1721</span></li><li class="country standard" id="iti-item-sk" role="option" data-dial-code="421" data-country-code="sk"><div class="flag-box"><div class="iti-flag sk"></div></div><span class="country-name">Slovakia (Slovensko)</span><span class="dial-code">+421</span></li><li class="country standard" id="iti-item-si" role="option" data-dial-code="386" data-country-code="si"><div class="flag-box"><div class="iti-flag si"></div></div><span class="country-name">Slovenia (Slovenija)</span><span class="dial-code">+386</span></li><li class="country standard" id="iti-item-sb" role="option" data-dial-code="677" data-country-code="sb"><div class="flag-box"><div class="iti-flag sb"></div></div><span class="country-name">Solomon Islands</span><span class="dial-code">+677</span></li><li class="country standard" id="iti-item-so" role="option" data-dial-code="252" data-country-code="so"><div class="flag-box"><div class="iti-flag so"></div></div><span class="country-name">Somalia (Soomaaliya)</span><span class="dial-code">+252</span></li><li class="country standard" id="iti-item-za" role="option" data-dial-code="27" data-country-code="za"><div class="flag-box"><div class="iti-flag za"></div></div><span class="country-name">South Africa</span><span class="dial-code">+27</span></li><li class="country standard" id="iti-item-kr" role="option" data-dial-code="82" data-country-code="kr"><div class="flag-box"><div class="iti-flag kr"></div></div><span class="country-name">South Korea (대한민국)</span><span class="dial-code">+82</span></li><li class="country standard" id="iti-item-ss" role="option" data-dial-code="211" data-country-code="ss"><div class="flag-box"><div class="iti-flag ss"></div></div><span class="country-name">South Sudan (‫جنوب السودان‬‎)</span><span class="dial-code">+211</span></li><li class="country standard" id="iti-item-es" role="option" data-dial-code="34" data-country-code="es"><div class="flag-box"><div class="iti-flag es"></div></div><span class="country-name">Spain (España)</span><span class="dial-code">+34</span></li><li class="country standard" id="iti-item-lk" role="option" data-dial-code="94" data-country-code="lk"><div class="flag-box"><div class="iti-flag lk"></div></div><span class="country-name">Sri Lanka (ශ්‍රී ලංකාව)</span><span class="dial-code">+94</span></li><li class="country standard" id="iti-item-sd" role="option" data-dial-code="249" data-country-code="sd"><div class="flag-box"><div class="iti-flag sd"></div></div><span class="country-name">Sudan (‫السودان‬‎)</span><span class="dial-code">+249</span></li><li class="country standard" id="iti-item-sr" role="option" data-dial-code="597" data-country-code="sr"><div class="flag-box"><div class="iti-flag sr"></div></div><span class="country-name">Suriname</span><span class="dial-code">+597</span></li><li class="country standard" id="iti-item-sj" role="option" data-dial-code="47" data-country-code="sj"><div class="flag-box"><div class="iti-flag sj"></div></div><span class="country-name">Svalbard and Jan Mayen</span><span class="dial-code">+47</span></li><li class="country standard" id="iti-item-sz" role="option" data-dial-code="268" data-country-code="sz"><div class="flag-box"><div class="iti-flag sz"></div></div><span class="country-name">Swaziland</span><span class="dial-code">+268</span></li><li class="country standard" id="iti-item-se" role="option" data-dial-code="46" data-country-code="se"><div class="flag-box"><div class="iti-flag se"></div></div><span class="country-name">Sweden (Sverige)</span><span class="dial-code">+46</span></li><li class="country standard" id="iti-item-ch" role="option" data-dial-code="41" data-country-code="ch"><div class="flag-box"><div class="iti-flag ch"></div></div><span class="country-name">Switzerland (Schweiz)</span><span class="dial-code">+41</span></li><li class="country standard" id="iti-item-sy" role="option" data-dial-code="963" data-country-code="sy"><div class="flag-box"><div class="iti-flag sy"></div></div><span class="country-name">Syria (‫سوريا‬‎)</span><span class="dial-code">+963</span></li><li class="country standard" id="iti-item-tw" role="option" data-dial-code="886" data-country-code="tw"><div class="flag-box"><div class="iti-flag tw"></div></div><span class="country-name">Taiwan (台灣)</span><span class="dial-code">+886</span></li><li class="country standard" id="iti-item-tj" role="option" data-dial-code="992" data-country-code="tj"><div class="flag-box"><div class="iti-flag tj"></div></div><span class="country-name">Tajikistan</span><span class="dial-code">+992</span></li><li class="country standard" id="iti-item-tz" role="option" data-dial-code="255" data-country-code="tz"><div class="flag-box"><div class="iti-flag tz"></div></div><span class="country-name">Tanzania</span><span class="dial-code">+255</span></li><li class="country standard" id="iti-item-th" role="option" data-dial-code="66" data-country-code="th"><div class="flag-box"><div class="iti-flag th"></div></div><span class="country-name">Thailand (ไทย)</span><span class="dial-code">+66</span></li><li class="country standard" id="iti-item-tl" role="option" data-dial-code="670" data-country-code="tl"><div class="flag-box"><div class="iti-flag tl"></div></div><span class="country-name">Timor-Leste</span><span class="dial-code">+670</span></li><li class="country standard" id="iti-item-tg" role="option" data-dial-code="228" data-country-code="tg"><div class="flag-box"><div class="iti-flag tg"></div></div><span class="country-name">Togo</span><span class="dial-code">+228</span></li><li class="country standard" id="iti-item-tk" role="option" data-dial-code="690" data-country-code="tk"><div class="flag-box"><div class="iti-flag tk"></div></div><span class="country-name">Tokelau</span><span class="dial-code">+690</span></li><li class="country standard" id="iti-item-to" role="option" data-dial-code="676" data-country-code="to"><div class="flag-box"><div class="iti-flag to"></div></div><span class="country-name">Tonga</span><span class="dial-code">+676</span></li><li class="country standard" id="iti-item-tt" role="option" data-dial-code="1868" data-country-code="tt"><div class="flag-box"><div class="iti-flag tt"></div></div><span class="country-name">Trinidad and Tobago</span><span class="dial-code">+1868</span></li><li class="country standard" id="iti-item-tn" role="option" data-dial-code="216" data-country-code="tn"><div class="flag-box"><div class="iti-flag tn"></div></div><span class="country-name">Tunisia (‫تونس‬‎)</span><span class="dial-code">+216</span></li><li class="country standard" id="iti-item-tr" role="option" data-dial-code="90" data-country-code="tr"><div class="flag-box"><div class="iti-flag tr"></div></div><span class="country-name">Turkey (Türkiye)</span><span class="dial-code">+90</span></li><li class="country standard" id="iti-item-tm" role="option" data-dial-code="993" data-country-code="tm"><div class="flag-box"><div class="iti-flag tm"></div></div><span class="country-name">Turkmenistan</span><span class="dial-code">+993</span></li><li class="country standard" id="iti-item-tc" role="option" data-dial-code="1649" data-country-code="tc"><div class="flag-box"><div class="iti-flag tc"></div></div><span class="country-name">Turks and Caicos Islands</span><span class="dial-code">+1649</span></li><li class="country standard" id="iti-item-tv" role="option" data-dial-code="688" data-country-code="tv"><div class="flag-box"><div class="iti-flag tv"></div></div><span class="country-name">Tuvalu</span><span class="dial-code">+688</span></li><li class="country standard" id="iti-item-vi" role="option" data-dial-code="1340" data-country-code="vi"><div class="flag-box"><div class="iti-flag vi"></div></div><span class="country-name">U.S. Virgin Islands</span><span class="dial-code">+1340</span></li><li class="country standard" id="iti-item-ug" role="option" data-dial-code="256" data-country-code="ug"><div class="flag-box"><div class="iti-flag ug"></div></div><span class="country-name">Uganda</span><span class="dial-code">+256</span></li><li class="country standard" id="iti-item-ua" role="option" data-dial-code="380" data-country-code="ua"><div class="flag-box"><div class="iti-flag ua"></div></div><span class="country-name">Ukraine (Україна)</span><span class="dial-code">+380</span></li><li class="country standard" id="iti-item-ae" role="option" data-dial-code="971" data-country-code="ae"><div class="flag-box"><div class="iti-flag ae"></div></div><span class="country-name">United Arab Emirates (‫الإمارات العربية المتحدة‬‎)</span><span class="dial-code">+971</span></li><li class="country standard" id="iti-item-gb" role="option" data-dial-code="44" data-country-code="gb"><div class="flag-box"><div class="iti-flag gb"></div></div><span class="country-name">United Kingdom</span><span class="dial-code">+44</span></li><li class="country standard" id="iti-item-us" role="option" data-dial-code="1" data-country-code="us"><div class="flag-box"><div class="iti-flag us"></div></div><span class="country-name">United States</span><span class="dial-code">+1</span></li><li class="country standard" id="iti-item-uy" role="option" data-dial-code="598" data-country-code="uy"><div class="flag-box"><div class="iti-flag uy"></div></div><span class="country-name">Uruguay</span><span class="dial-code">+598</span></li><li class="country standard" id="iti-item-uz" role="option" data-dial-code="998" data-country-code="uz"><div class="flag-box"><div class="iti-flag uz"></div></div><span class="country-name">Uzbekistan (Oʻzbekiston)</span><span class="dial-code">+998</span></li><li class="country standard" id="iti-item-vu" role="option" data-dial-code="678" data-country-code="vu"><div class="flag-box"><div class="iti-flag vu"></div></div><span class="country-name">Vanuatu</span><span class="dial-code">+678</span></li><li class="country standard" id="iti-item-va" role="option" data-dial-code="39" data-country-code="va"><div class="flag-box"><div class="iti-flag va"></div></div><span class="country-name">Vatican City (Città del Vaticano)</span><span class="dial-code">+39</span></li><li class="country standard" id="iti-item-ve" role="option" data-dial-code="58" data-country-code="ve"><div class="flag-box"><div class="iti-flag ve"></div></div><span class="country-name">Venezuela</span><span class="dial-code">+58</span></li><li class="country standard" id="iti-item-vn" role="option" data-dial-code="84" data-country-code="vn"><div class="flag-box"><div class="iti-flag vn"></div></div><span class="country-name">Vietnam (Việt Nam)</span><span class="dial-code">+84</span></li><li class="country standard" id="iti-item-wf" role="option" data-dial-code="681" data-country-code="wf"><div class="flag-box"><div class="iti-flag wf"></div></div><span class="country-name">Wallis and Futuna (Wallis-et-Futuna)</span><span class="dial-code">+681</span></li><li class="country standard" id="iti-item-eh" role="option" data-dial-code="212" data-country-code="eh"><div class="flag-box"><div class="iti-flag eh"></div></div><span class="country-name">Western Sahara (‫الصحراء الغربية‬‎)</span><span class="dial-code">+212</span></li><li class="country standard" id="iti-item-ye" role="option" data-dial-code="967" data-country-code="ye"><div class="flag-box"><div class="iti-flag ye"></div></div><span class="country-name">Yemen (‫اليمن‬‎)</span><span class="dial-code">+967</span></li><li class="country standard" id="iti-item-zm" role="option" data-dial-code="260" data-country-code="zm"><div class="flag-box"><div class="iti-flag zm"></div></div><span class="country-name">Zambia</span><span class="dial-code">+260</span></li><li class="country standard" id="iti-item-zw" role="option" data-dial-code="263" data-country-code="zw"><div class="flag-box"><div class="iti-flag zw"></div></div><span class="country-name">Zimbabwe</span><span class="dial-code">+263</span></li><li class="country standard" id="iti-item-ax" role="option" data-dial-code="358" data-country-code="ax"><div class="flag-box"><div class="iti-flag ax"></div></div><span class="country-name">Åland Islands</span><span class="dial-code">+358</span></li></ul>

3 个答案:

答案 0 :(得分:2)

要访问data attributes,您可以使用data method

$('#iti-item-dz').data('dial-code') // will return the number 213

要获取所有li使用的所有拨号代码,请使用

let dialCodes = []

$('#country-listbox li').each(function() {
    dialCodes.push($(this).data('dial-code'))
})

要获取所单击列表项的拨号代码,请使用此

let dialCode

$('#country-listbox li').on('click', function() {
    dialCode = $(this).data('dial-code')
})

答案 1 :(得分:0)

您尝试获取列表项的属性,只需在.on()内部调用它即可。

  private ObservableCollection<string> m_myCollection;
  public ObservableCollection<string> MyCollection
  {
     get => m_myCollection;
     set
     {
        m_myCollection= value;
        OnPropertyChanged();
     }
  }

  public ViewModel()
  {
     MyCollection = new ObservableCollection<string>();

     MyCollection.CollectionChanged += OnCollectionChanged;

     MyCollection.Add("Item 1");
  }

  private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
  {
     // How to get the name of the collection here? That is: "MyCollection"
  }

答案 2 :(得分:0)

只需使用在ul标记中的父类,并使用this上下文来获取被点击项的值。 然后您将通过单击项目获得所有项目列表数据。

运行以下代码段

$('.country-list .country').on('click', function() {
    var country = $(this).find('.country-name').text();
    alert(country);
  });

$(document).ready(function() {
  $('.country-list .country').on('click', function() {
    var country = $(this).find('.country-name').text();
    alert(country);
  });
})
.country {
  display: block;
  padding: 5px;
  background: gray;
  cursor: pointer;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul class="country-list hide" id="country-listbox" aria-expanded="false" role="listbox" aria-activedescendant="iti-item-al">
  <li class="country preferred" id="iti-item-fr" role="option" data-dial-code="33" data-country-code="fr" aria-selected="false">
    <div class="flag-box">
      <div class="iti-flag fr"></div>
    </div><span class="country-name">France</span><span class="dial-code">+33</span></li>
  <li class="divider" role="separator" aria-disabled="true"></li>
  <li class="country standard" id="iti-item-af" role="option" data-dial-code="93" data-country-code="af">
    <div class="flag-box">
      <div class="iti-flag af"></div>
    </div><span class="country-name">Afghanistan (‫افغانستان‬‎)</span><span class="dial-code">+93</span></li>
  <li class="country standard highlight active" id="iti-item-al" role="option" data-dial-code="355" data-country-code="al" aria-selected="true">
    <div class="flag-box">
      <div class="iti-flag al"></div>
    </div><span class="country-name">Albania (Shqipëri)</span><span class="dial-code">+355</span></li>
  <li class="country standard" id="iti-item-dz" role="option" data-dial-code="213" data-country-code="dz">
    <div class="flag-box">
      <div class="iti-flag dz"></div>
    </div><span class="country-name">Algeria (‫الجزائر‬‎)</span><span class="dial-code">+213</span></li>
  <li class="country standard" id="iti-item-as" role="option" data-dial-code="1684" data-country-code="as">
    <div class="flag-box">
      <div class="iti-flag as"></div>
    </div><span class="country-name">American Samoa</span><span class="dial-code">+1684</span></li>
  <li class="country standard" id="iti-item-ad" role="option" data-dial-code="376" data-country-code="ad">
    <div class="flag-box">
      <div class="iti-flag ad"></div>
    </div><span class="country-name">Andorra</span><span class="dial-code">+376</span></li>
  <li class="country standard" id="iti-item-ao" role="option" data-dial-code="244" data-country-code="ao">
    <div class="flag-box">
      <div class="iti-flag ao"></div>
    </div><span class="country-name">Angola</span><span class="dial-code">+244</span></li>
  <li class="country standard" id="iti-item-ai" role="option" data-dial-code="1264" data-country-code="ai">
    <div class="flag-box">
      <div class="iti-flag ai"></div>
    </div><span class="country-name">Anguilla</span><span class="dial-code">+1264</span></li>
  <li class="country standard" id="iti-item-ag" role="option" data-dial-code="1268" data-country-code="ag">
    <div class="flag-box">
      <div class="iti-flag ag"></div>
    </div><span class="country-name">Antigua and Barbuda</span><span class="dial-code">+1268</span></li>
  <li class="country standard" id="iti-item-ar" role="option" data-dial-code="54" data-country-code="ar">
    <div class="flag-box">
      <div class="iti-flag ar"></div>
    </div><span class="country-name">Argentina</span><span class="dial-code">+54</span></li>
  <li class="country standard" id="iti-item-am" role="option" data-dial-code="374" data-country-code="am">
    <div class="flag-box">
      <div class="iti-flag am"></div>
    </div><span class="country-name">Armenia (Հայաստան)</span><span class="dial-code">+374</span></li>
  <li class="country standard" id="iti-item-aw" role="option" data-dial-code="297" data-country-code="aw">
    <div class="flag-box">
      <div class="iti-flag aw"></div>
    </div><span class="country-name">Aruba</span><span class="dial-code">+297</span></li>
  <li class="country standard" id="iti-item-au" role="option" data-dial-code="61" data-country-code="au">
    <div class="flag-box">
      <div class="iti-flag au"></div>
    </div><span class="country-name">Australia</span><span class="dial-code">+61</span></li>
  <li class="country standard" id="iti-item-at" role="option" data-dial-code="43" data-country-code="at">
    <div class="flag-box">
      <div class="iti-flag at"></div>
    </div><span class="country-name">Austria (Österreich)</span><span class="dial-code">+43</span></li>
  <li class="country standard" id="iti-item-az" role="option" data-dial-code="994" data-country-code="az">
    <div class="flag-box">
      <div class="iti-flag az"></div>
    </div><span class="country-name">Azerbaijan (Azərbaycan)</span><span class="dial-code">+994</span></li>
  <li class="country standard" id="iti-item-bs" role="option" data-dial-code="1242" data-country-code="bs">
    <div class="flag-box">
      <div class="iti-flag bs"></div>
    </div><span class="country-name">Bahamas</span><span class="dial-code">+1242</span></li>
  <li class="country standard" id="iti-item-bh" role="option" data-dial-code="973" data-country-code="bh">
    <div class="flag-box">
      <div class="iti-flag bh"></div>
    </div><span class="country-name">Bahrain (‫البحرين‬‎)</span><span class="dial-code">+973</span></li>
  <li class="country standard" id="iti-item-bd" role="option" data-dial-code="880" data-country-code="bd">
    <div class="flag-box">
      <div class="iti-flag bd"></div>
    </div><span class="country-name">Bangladesh (বাংলাদেশ)</span><span class="dial-code">+880</span></li>
  <li class="country standard" id="iti-item-bb" role="option" data-dial-code="1246" data-country-code="bb">
    <div class="flag-box">
      <div class="iti-flag bb"></div>
    </div><span class="country-name">Barbados</span><span class="dial-code">+1246</span></li>
  <li class="country standard" id="iti-item-by" role="option" data-dial-code="375" data-country-code="by">
    <div class="flag-box">
      <div class="iti-flag by"></div>
    </div><span class="country-name">Belarus (Беларусь)</span><span class="dial-code">+375</span></li>
  <li class="country standard" id="iti-item-be" role="option" data-dial-code="32" data-country-code="be">
    <div class="flag-box">
      <div class="iti-flag be"></div>
    </div><span class="country-name">Belgium (België)</span><span class="dial-code">+32</span></li>
  <li class="country standard" id="iti-item-bz" role="option" data-dial-code="501" data-country-code="bz">
    <div class="flag-box">
      <div class="iti-flag bz"></div>
    </div><span class="country-name">Belize</span><span class="dial-code">+501</span></li>
  <li class="country standard" id="iti-item-bj" role="option" data-dial-code="229" data-country-code="bj">
    <div class="flag-box">
      <div class="iti-flag bj"></div>
    </div><span class="country-name">Benin (Bénin)</span><span class="dial-code">+229</span></li>
  <li class="country standard" id="iti-item-bm" role="option" data-dial-code="1441" data-country-code="bm">
    <div class="flag-box">
      <div class="iti-flag bm"></div>
    </div><span class="country-name">Bermuda</span><span class="dial-code">+1441</span></li>
  <li class="country standard" id="iti-item-bt" role="option" data-dial-code="975" data-country-code="bt">
    <div class="flag-box">
      <div class="iti-flag bt"></div>
    </div><span class="country-name">Bhutan (འབྲུག)</span><span class="dial-code">+975</span></li>
  <li class="country standard" id="iti-item-eg" role="option" data-dial-code="20" data-country-code="eg">
    <div class="flag-box">
      <div class="iti-flag eg"></div>
    </div><span class="country-name">Egypt (‫مصر‬‎)</span><span class="dial-code">+20</span></li>
  <li class="country standard" id="iti-item-sv" role="option" data-dial-code="503" data-country-code="sv">
    <div class="flag-box">
      <div class="iti-flag sv"></div>
    </div><span class="country-name">El Salvador</span><span class="dial-code">+503</span></li>
</ul>