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.