use*_*027 2 jquery html5 select custom-attributes
如果我有这个:
<span data-helo="1">something</span>
<span data-helo="2">something different</span>
Run Code Online (Sandbox Code Playgroud)
我想针对第一个跨度,我应该怎么做?
我尝试过类似的东西:
$('span').data('helo', '1')
Run Code Online (Sandbox Code Playgroud)
但它返回了两个跨度.
尝试:
$('span[data-helo="1"]')
Run Code Online (Sandbox Code Playgroud)
这将span使用data-helo-attribute值定位所有元素1.
用你的代码:
$('span').data('helo', '1')
Run Code Online (Sandbox Code Playgroud)
您要定位所有span元素并将其data-helo属性设置为1.然后返回该集合(通过典型的jQuery链接).