我有很多元素,例如
<input tag="data-initial-222" value="" type="checkbox">
<input tag="data-initial-111" value="" type="checkbox">
如何选择具有此标签“data-initial-*”的所有元素
另一个问题是:
如何选择
<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.
关于jquery - 如何在jquery中选择动态数据属性元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44919023/