Home >Web Front-end >JS Tutorial >jQuery operation drop-down list box implementation code_jquery

jQuery operation drop-down list box implementation code_jquery

WBOY
WBOYOriginal
2016-05-16 18:34:08915browse


1. Get the jQuery object
obj = $('#select1');

2. Get the length of Options
len = $('#select1 option').length

3. Traverse options
for (var i = 0; i option_value = obj[0].options[i].value;
option_text = obj [0].options[i].text;
}

4. Get the selected value
obj_value = $('#select1').val();

5. Get the text corresponding to the selected value
obj_text = obj[0].options[obj[0].selectedIndex].text;

6. Add an option
obj.append(' ');

7. Delete an option
$('#select1 option[value="1"]').remove();
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn