JQuery operation drop-down box and jQuery operation drop-down box
Today, I brainstormed and dug a hole for myself, but I knew this problem better.
The START is as follows:
<Select id = "province-select"> <option> select province </option> <option class = 'Pro _ id' pro_id = "1"> name1 </option> <option class = 'Pro _ id' pro_id = "2"> name2 </option> <option class = 'Pro _ id' pro_id = "3"> name3 </option> <option class = 'Pro _ id' pro_id = "4"> name4 </option> <option class = 'Pro _ id' pro_id = "5"> name5 </option> <option class = 'Pro _ id' pro_id = "6"> name6 </option> </select> <script> $ ('. pro-select '). click (function () {var province_id = $ (this ). attr ('Pro _ id'); var province_response = xxx. ajaxRequest ('<{flink ctl = "city: city_list"}>', {'vince _ id': province_id}, false ); var city_list = '<option> select city </option>'; for (pro_id in province_response) {console. log (province_response [pro_id]. link); city_list + = '<option class = "city-name" href = "' + province_response [pro_id]. link + '">' + province_response [pro_id]. name + '</option>';} parameter ('{city-select'{.html (city_list) ;}); </script>
Then I found that this js Code was not triggered in my life and death, and then Baidu ...... I found myself wrong.
<Select> the tag is triggered by Onchange ...... So I wrote the following code:
<Select id = "province-select"> <option> select province </option> <option value = "1"> name1 </option> <option value = "2"> name2 </option> <option value = "3"> name3 </option> <option value = "4"> name4 </option> <option value = "5"> name5 </option> <option value = "6"> nam6e </option> </select> <script >$ ('# province-select '). change (function () {var province_id = $ (this ). val (); var province_response = xxx. ajaxRequest ('<{flink ctl = "city: city_list"}>', {'vince _ id': province_id}, false ); var city_list = '<option> select city </option>'; for (pro_id in province_response) {city_list + = '<option class = "city-name" href = "' + province_response [pro_id]. link + '">' + province_response [pro_id]. name + '</option>';} parameter ('{city-select'{.html (city_list) ;}); </script>
Solve the problem ~
Another method was found just now:
<script> $(this).find('option:selected').html(); $(this).find('option:selected').attr();</script>