jquery - 如何在jquery中选择动态数据属性元素

标签 jquery jquery-ui custom-data-attribute

我有很多元素,例如

<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">

  1. 使用starts with selector

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/

    相关文章:

    jquery - CSS 不响应通过 jQuery 设置的数据属性

    javascript - 使用 URL 编码/解码从用户输入到 HTML5 数据属性的转义/特殊字符

    javascript - 使用Node.JS查询MySQL并在网页中显示结果

    javascript - 如何使用 jQuery 按名称检索值数组?

    javascript - 当 jQueryUI 对话框没有 ID 时打开它

    jquery-ui - 打开 jQuery UI 对话框后 CKEditor 不工作

    jquery - 如何编写一个 jQuery 函数将 data-id 循环以显示某个元素?

    javascript - jQuery - 刷新页面后不起作用

    javascript - 如果部分 url 匹配,则突出显示父菜单

    jquery - 图像悬停效果-jquery