我需要在某些情况下从选择中删除一个选项.
基本上:
if(mystatement == true)
{
//remove item with id 'option1' from select of id 'select1'
}
Run Code Online (Sandbox Code Playgroud)
有人知道我的代码来实现这个目标吗?
非常感谢.
gna*_*arf 14
按值删除:
$("#select1 option[value=1]").remove();
Run Code Online (Sandbox Code Playgroud)
按文字删除:
$("#select1 option:contains(Text)").remove();
Run Code Online (Sandbox Code Playgroud)
编辑
由于id在文档中是唯一的,因此无需将其与父选择元素相关联.你可以做的很简单
$("#option1").remove();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
27604 次 |
| 最近记录: |