JQuery operation drop-down box and jQuery operation drop-down box

Source: Internet
Author: User

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>

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.