jQuery从select中删除选项 [英] jQuery remove options from select
本文介绍了jQuery从select中删除选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含5个选项的页面,所有页面都有一个类名'ct'。我需要在运行onclick事件时从每个选择中删除值为X的选项。我的代码是:
I have a page with 5 selects that all have a class name 'ct'. I need to remove the option with a value of 'X' from each select while running an onclick event. My code is:
$(".ct").each(function() {
$(this).find('X').remove();
});
我哪里错了?
推荐答案
试试这个:
$(".ct option[value='X']").each(function() {
$(this).remove();
});
或者更简洁一点,这也可行:
Or to be more terse, this will work just as well:
$(".ct option[value='X']").remove();
这篇关于jQuery从select中删除选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文