Jquery implements dynamic operation select selection, jqueryselect

Source: Internet
Author: User

Jquery implements dynamic operation select selection, jqueryselect

Today, because of the need for dynamic select operations for projects, I found many results on Baidu. I tried one of them and found that they could not be used. the second and second discoveries are the same, and I did a little research.

Copy codeThe Code is as follows:
// Initialize select, the first selected
$ ('# StoStoreCategoryID'). get (0). selectedIndex = 0;
$ ("# StoStoreCategoryID option"). each (function (I, n ){
If ($ (n). text () = data. scName)
{
$ (N). attr ("selected", true );
}
})

Here, we can determine whether the text is the same. If you want to determine whether the value is the same

Copy codeThe Code is as follows:
If ($ (n). val () = data. scName)

I can see this code on the Internet.

Copy codeThe Code is as follows:
// Set text to pxx
$ (". Selector"). find ("option [text = 'pxx']"). attr ("selected", true );

It seems feasible, but the operation is not successful.

The writing is relatively simple. It was not intended to be prepared, but it had a lot of time to worry about it. I also kept it for myself while sending it to others.

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.