Jquery Div更改不受脚本影响

时间:2015-10-10 04:10:36

标签: javascript jquery html ajax

我有一个有多个下拉菜单的div。下拉列表没有任何ID。我正在使用其他一些逻辑删除并添加div中的下拉列表。如果我删除下拉菜单意味着更改不会影响相同的脚本。

$(document).ready(function () {
$(function () { 
   alert($('#show_lable_categories').find('select').length)); // return 5
   //Now Remove some dropdowns
   $('#show_value_categories').find("select").slice(2).remove();
   alert($('#show_lable_categories').find('select').length)); //Always return 5 //I need 3 Instead of 5 with in the script

});
});

1 个答案:

答案 0 :(得分:1)

 $('#show_value_categories').find("select").slice(2).remove();

我认为问题可能是您在选择的元素上输了一个错误,从$('show_value_categories')变为$('#show_lable_categories')。

同样正如小费一样,您希望拥有一个变量,例如:

var dropdown = $('#show_value_categories')

避免这些错误以及不必两次找到相同的元素。