如何 select jquery 中的动态数据属性元素
how to select dynamic data-attribute element in jquery
我有很多像
这样的元素
<input tag="data-initial-222" value="" type="checkbox">
<input tag="data-initial-111" value="" type="checkbox">
我怎样才能select拥有这个标签的所有元素"data-initial-*"
另一个问题是:
如何select
<input data-initial="111" type="checkbox">
或
<input data-initial="222" type="checkbox">
使用数据初始属性。
console.log($("input[data-initial]").length)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input tag="data-initial-222" value="" type="checkbox">
<input data-initial="111" value="" type="checkbox">
<input data-initial="222" value="" type="checkbox">
<input data-initial="333" value="" type="checkbox">
Description: Selects elements that have the specified attribute with a value beginning exactly with a given string.
- Attribute selector
Description: Selects elements that have the specified attribute, with any value.
$( "input[tag*='data-initial']" )
我有很多像
这样的元素<input tag="data-initial-222" value="" type="checkbox">
<input tag="data-initial-111" value="" type="checkbox">
我怎样才能select拥有这个标签的所有元素"data-initial-*"
另一个问题是:
如何select
<input data-initial="111" type="checkbox">
或
<input data-initial="222" type="checkbox">
使用数据初始属性。
console.log($("input[data-initial]").length)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input tag="data-initial-222" value="" type="checkbox">
<input data-initial="111" value="" type="checkbox">
<input data-initial="222" value="" type="checkbox">
<input data-initial="333" value="" type="checkbox">
Description: Selects elements that have the specified attribute with a value beginning exactly with a given string.
- Attribute selector
Description: Selects elements that have the specified attribute, with any value.
$( "input[tag*='data-initial']" )