如何使用Jquery动态查找html链接的属性并用逗号标记ref属性?
想象一下,我有一个动态填充的水果名称列表,由 php 生成的代码如下
<div id="fruit_list">
<ol>
<li>Apple <a id='1' ref='red'>Delete</a></li>
<li>Pear <a href id='2' ref='green'>Delete</a></li>
</ol>
</div>
我想做一个 ajax 删除,当用户单击“fruit_list div”下的“删除”链接时,在单击“删除”链接时,我想要知道单击的链接的属性 id 和 ref。知道属性后,我如何在 jQuery 中分解它,以便可以用逗号分隔 ref。
如果我错了,你能建议一个方法吗?
Imagine i have a list of fruit names being dynamically populated and the codes generated by php is as follows
<div id="fruit_list">
<ol>
<li>Apple <a id='1' ref='red'>Delete</a></li>
<li>Pear <a href id='2' ref='green'>Delete</a></li>
</ol>
</div>
I want to do a ajax delete where when the user clicks delete link, under the fruit_list div and while onclick of the delete link, i want to know the attributes id and ref of the clicked link. Upon knowing attributes, how could i explode it in jQuery so that the ref can be seperated by the comma.
Can you suggest an approch if i am wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试:
Try:
没听说过 ref 属性。而且你不应该自己编造。您可以使用它的数据属性(data-ref=value)。
或者你可以这样做 http://jsfiddle.net/gmrcn/6/
HTML
JS
Haven't heard of an ref attribute. And you shouldn't make up your own. You could use the data attribute for it (data-ref=value).
Or you could do it like this http://jsfiddle.net/gmrcn/6/
HTML
JS
我不太明白你到底在问什么。但我会按如下方式实现删除功能。
I don't quite understand what exactly you are asking. But i would implement delete function as follows.