Jam*_*ord 2 html javascript jquery
我有
<select name="saved" class="saved" multiple="multiple">
<option value="1">Hello</option>
<option value="2">Goodbye</option>
<option value="3">Wave</option>
</select>
Run Code Online (Sandbox Code Playgroud)
如果在if语句的"saved"中已经存在value ="2"的选项,我将如何检查Jquery
我希望看看它是否存在 - 如果它被选中则不存在.
我在一个可以在多个选择框上运行的函数中使用它.选择框的类名现在存储为var"theSel" - 我该如何修改它
und*_*ned 10
你可以使用length财产:
if ($('select.saved option[value="2"]').length) {
// exists
}
Run Code Online (Sandbox Code Playgroud)
$(document).ready(function(){
// ...
if ($('select.'+theSel+' option[value="'+theValue+'"]').length) {
// exists
}
})
Run Code Online (Sandbox Code Playgroud)