以声明方式设置 HTML 链接的 jQuery.Data 属性
假设我在数据网格或中继器内的行中有一个 HTML 链接
<a href="javascript:void(0);" class="DoSomething">DoSomething</a>
现在还假设我已经处理了 jQuery 中所有 DoSomethings 的单击事件,
$(".DoSomething").click(function (e) {
//Make my DoSomethings do something
});
将数据传递到依赖于的单击事件的正确技术是什么点击链接?
如果没有 jQuery,您通常会做这样的事情。
<a href="javascript:void(0);" class="DoSomething" onclick="DoSomething('<%# Eval("SomeValue") %>');">DoSomething</a>
但这种技术显然不适用于 jQuery 的情况。
基本上,我的理想解决方案将以某种方式为单击的链接的 jQuery.Data 属性添加值,但以声明方式执行此操作。
Assuming I have a HTML link in my rows inside a datagrid or repeater as such
<a href="javascript:void(0);" class="DoSomething">DoSomething</a>
Now also assuming that I have handled the click event for all my DoSomethings in jQuery as such
$(".DoSomething").click(function (e) {
//Make my DoSomethings do something
});
What is the correct technique for passing data to the click event that is dependent on the link clicked?
Without jQuery you would typically do something like this.
<a href="javascript:void(0);" class="DoSomething" onclick="DoSomething('<%# Eval("SomeValue") %>');">DoSomething</a>
but this technique obviously doesn't work in the jQuery case.
Basically my ideal solution would somehow add values for to the jQuery.Data property for the link clicked but doing so declaratively.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 HTML5 数据属性。 1.4.3+ 内置 jQuery 支持
http://api.jquery.com/data/#数据2
Use HTML5 data- attributes. jQuery support is built-in for 1.4.3+
http://api.jquery.com/data/#data2
您可以使用 attr() 函数。
http://api.jquery.com/attr/
You could use the attr() function.
http://api.jquery.com/attr/
我不清楚你的问题,但这可能会有所帮助
your question was not clear to me but may be this will help