jQuery匹配多个属性 [英] jQuery match multiple attributes
本文介绍了jQuery匹配多个属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下标记,并且想要使 All
单选按钮被选中。
< UL>
< li>< input type =radiovalue =Allname =Foo/>全部< / li>
< li>< input type =radiovalue =Newname =Foo/>新< / li>
< li>< input type =radiovalue =Removedname =Foo/>已删除< / li>
< li>< input type =radiovalue =Updatedname =Foo/>已更新< / li>
< / ul>
我想通过属性匹配,但我需要匹配2个属性 @ name ='Foo'
和 @ value ='All'
。
像这样的东西:
$(input [@ name ='Foo'@ value ='all']) .attr( '检查', '检查');
有人可以证明这可以做到吗?
解决方案
以下HTML文件显示了您可以如何执行此操作:
< HTML>
< head>
< script type =text / javascriptsrc =jquery-1.2.6.pack.js>< / script>
< script type =text / javascript>
$(document).ready(function(){
$(a)。click(function(event){
$(input [name ='Foo'] [value ='All'])。attr('checked','checked');
event.preventDefault();
});
});
< / script>
< / head>
< body>
< ul>
< li>< input type =radiovalue =Allname =Foo/>全部< / li>
< li>< input type =radiovalue =Newname =Foo/>新< / li>
< li>< input type =radiovalue =Removedname =Foo/>已删除< / li>
< li>< input type =radiovalue =Updatedname =Foo/>已更新< / li>
< / ul>
< a href =>点击此处< / a>
< / body>
< / html>
当您点击链接时,所需单选按钮被选中。重要的一行是设置选中的
属性。
I have the following markup, and I want to make the All
radio button checked.
<ul>
<li><input type="radio" value="All" name="Foo"/>All</li>
<li><input type="radio" value="New" name="Foo"/>New</li>
<li><input type="radio" value="Removed" name="Foo"/>Removed</li>
<li><input type="radio" value="Updated" name="Foo"/>Updated</li>
</ul>
I'd like to match via attribute, but I need to match on 2 attributes, @name='Foo'
and @value='All'
.
Something like this:
$("input[@name='Foo' @value='all']").attr('checked','checked');
Can someone show how this can be done?
解决方案
The following HTML file shows how you can do this:
<html>
<head>
<script type="text/javascript" src="jquery-1.2.6.pack.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("a").click(function(event){
$("input[name='Foo'][value='All']").attr('checked','checked');
event.preventDefault();
});
});
</script>
</head>
<body>
<ul>
<li><input type="radio" value="All" name="Foo" />All</li>
<li><input type="radio" value="New" name="Foo" />New</li>
<li><input type="radio" value="Removed" name="Foo" />Removed</li>
<li><input type="radio" value="Updated" name="Foo" />Updated</li>
</ul>
<a href="" >Click here</a>
</body>
</html>
When you click on the link, the desired radio button is selected. The important line is the one setting the checked
attribute.
这篇关于jQuery匹配多个属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文