如何写下面的陈述
if ($('#SelectedItems option[value=' + optionData.Value + ']').length === 0) ;
使用变量
var selectedItems = $('#SelectedItems');
//Something like this but not exactly
if ($(**selectedItems** + "option[value=' + optionData.Value + ']").length === 0) ;
答案 0 :(得分:0)
if ($('option[value="' + optionData.Value + '"]',$('#SelectedItems')).length === 0)
答案 1 :(得分:0)
我想你想要这个
if ($("option[value='" + optionData.Value + "']", selectedItems).length === 0)
这会选择selectedItems
中与选择器"option[value='" + optionData.Value + "']"
匹配的元素的所有后代。
答案 2 :(得分:0)
if (selectedItems.find("option[value='" + optionData.value + "']").length === 0)
应该做你想要的。