开发者

jquery select list remove

there are 2 multiple select list on my page , one is there with a seperate remove button . selecting an item there in the selected list is removing the item from the first select list also.how will i specify which list to remove item from in thi开发者_JAVA技巧s code

$().ready(function() {    
   $('#remove').click(function() {    
       return !$('#FeatureList option:selected').remove();      
   });         
});


If the list is relative, like this:

<select>...options...</select>
<input type="button" class="remove" />

You can do it like this:

$(function() {
  $('.remove').click(function() {
    $(this).prev('select').find('option:selected').remove();
  });  
}); 

Currently your code has IDs, leading me to believe you're using the same ID multiple times...this is invalid HTML, for a list that may appear n number of times, you should use classes and find the list relative to the button. If that's not possible, each combination needs unique IDs or classes.

Also, try and refrain from using $().ready as it's deprecated in jQuery 1.4+, you should use $(document).ready(func); or the shorter version: $(func);.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜