In js, clear option before option is cleared. My approach is to traverse the existing option and leave each sub-element empty. In js, clear option before option is cleared. My approach is to traverse the existing option and leave each sub-element empty. Now we use jQuery to implement it. We only need to call the empty method supported by jQuery.
Empty ()
Delete all child nodes in the matched element set.
In addition, we need to set the default value. So here we can clear all the options in the select statement and use the following statement:
The Code is as follows:
$ ('# Selectid'). empty (). append ($ ("Set the default value here."));
Create option dynamically in js
The previous method was to use its intermediate function to traverse json objects returned by Ajax. And use the new Option to create the option. Now I use the following method to handle it:
The Code is as follows:
For (var I = 0, len = jsondata. length; I $ ('# Selectid'). append ($ (" "Maid +""));
}
It seems that you can write it like this:
The Code is as follows:
$ ('# Selectid'). append (""Maid +"");