Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/459.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 声明式设置HTML链接的jQuery.Data属性_Javascript_Jquery_Asp.net_Repeater_Declarative - Fatal编程技术网

Javascript 声明式设置HTML链接的jQuery.Data属性

Javascript 声明式设置HTML链接的jQuery.Data属性,javascript,jquery,asp.net,repeater,declarative,Javascript,Jquery,Asp.net,Repeater,Declarative,假设我在datagrid或repeater中的行中有一个HTML链接 <a href="javascript:void(0);" class="DoSomething">DoSomething</a> 向依赖于所单击链接的单击事件传递数据的正确方法是什么 如果没有jQuery,您通常会这样做 <a href="javascript:void(0);" class="DoSomething" onclick="DoSomething('<%# Eval("So

假设我在datagrid或repeater中的行中有一个HTML链接

<a href="javascript:void(0);" class="DoSomething">DoSomething</a>
向依赖于所单击链接的单击事件传递数据的正确方法是什么

如果没有jQuery,您通常会这样做

<a href="javascript:void(0);" class="DoSomething" onclick="DoSomething('<%# Eval("SomeValue") %>');">DoSomething</a>

但是这种技术显然不适用于jQuery

基本上,我的理想解决方案是以某种方式为已单击但以声明方式执行的链接的jQuery.Data属性添加值

您可以使用attr()函数


我不清楚你的问题,但这可能会有所帮助

$(".DoSomething").click(function (e) {
    //Make my DoSomethings do something
    $(this).data("key","value");
    //later the value can be retrieved like
    var value=$(this).data("key");
    console.log(value);// gives you "value"
});

使用HTML5数据属性。jQuery支持内置于1.4.3中+


$('.product link')。单击(函数(e){
警报($(this.data('productid'));
});
$("#Something").attr("your-value", "Hello World");

$("#Something").click(function (e) {
    //Make my DoSomethings do something
   var value = $(this).attr("your-value");
   alert(value); // Alerts Hello World

});
$(".DoSomething").click(function (e) {
    //Make my DoSomethings do something
    $(this).data("key","value");
    //later the value can be retrieved like
    var value=$(this).data("key");
    console.log(value);// gives you "value"
});
 <a href="#" class="product-link" data-productid="77">click here</a>

 $('.product-link').click(function (e) {
     alert($(this).data('productid'));
 });