jQuery 如何找到带有“value=x”的元素?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6732364/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to find elements with 'value=x'?
提问by daGrevis
I need to remove element that have value="123"
. I know that all elements with different values are located into #attached_docs
, but I don't know how to select element with value="123"
.
我需要删除具有value="123"
. 我知道所有具有不同值的元素都位于 中#attached_docs
,但我不知道如何使用value="123"
.
$('#attached_docs').find ... .remove();
Can you help me?
你能帮助我吗?
回答by Gabriele Petrioli
If the value is hardcoded in the source of the page using the value
attribute then you can
如果使用该value
属性在页面源中对该值进行了硬编码,则您可以
$('#attached_docs :input[value="123"]').remove();
If you want to target elements that have a value of EDITworks both ways..123
, which was set by the user or programmatically then use
如果要定位具有值的元素,该值方式123
是由用户设置的或以编程设置的,则使用EDIT可以双向工作..
or
或者
$('#attached_docs :input').filter(function(){return this.value=='123'}).remove();
回答by álvaro González
Value exactly equal to 123:
值正好等于 123:
jQuery("#attached_docs[value='123']")
Full reference: http://api.jquery.com/category/selectors/
回答by Gazler
Use the following selector.
使用以下选择器。
$('#attached_docs [value=123]').remove();
回答by genesis
$('#attached_docs [value="123"]').find ... .remove();
it should do your need however, you cannot duplicate id! remember it
它应该满足您的需要,但是您不能重复 ID!记住它
回答by Ari
The following worked for me:
以下对我有用:
$("[id=attached_docs][value=123]")