3 回答
TA贡献1818条经验 获得超11个赞
$('*[data-customerID="22"]');
*
document.querySelector{,all}
22
)
.dataAttr('foo')
.attr('data-foo')
).
TA贡献1998条经验 获得超6个赞
$("[data-test]")
<div data-test=value>attributes with values</div><div data-test>attributes without values</div>
$('[data-test~="foo"]')
foo
<div data-test="foo">Exact Matches</div><div data-test="this has the word foo">Where the Attribute merely contains "foo"</div>
$('[data-test="the_exact_value"]')
the_exact_value
<div data-test="the_exact_value">Exact Matches</div>
<div data-test="the_exact_value foo">This won't match</div>
TA贡献1804条经验 获得超2个赞
$('[data-whatever="myvalue"]')
$(...).data(...)
.find
var $container = $('<div><div id="item1"/><div id="item2"/></div>');
// add html attribute
var $item1 = $('#item1').attr('data-generated', true);
// add as data
var $item2 = $('#item2').data('generated', true);
// create item, add data attribute via jquery
var $item3 = $('<div />', {id: 'item3', data: { generated: 'true' }, text: 'Item 3' });
$container.append($item3);
// create item, "manually" add data attribute
var $item4 = $('<div id="item4" data-generated="true">Item 4</div>');
$container.append($item4);
// only returns $item1 and $item4
var $result = $container.find('[data-generated="true"]');
- 3 回答
- 0 关注
- 625 浏览
添加回答
举报