javascript – 调用onClick函数并从元素的data- *属性传递一个值

我有这样的链接

<li><a href="#" data-value="Codes">Get codes</a></li>
<li><a href="#" data-value="Product">Get products</a></li>

我怎样才能这样做,当我点击链接然后调用一个函数传递数据值中包含的值?

function refreshGrid(value) { }

解决方法:

请尝试以下方法

$('li > a[href="#"][data-value]').click(function (e) { // On click of all anchors with a data-value attribute and a href of # that are immediate children of li elements (nb this selector can be modifed to suit your needs)
  e.preventDefault(); // prevent the default (navigate to href)
  refreshGrid($(this).data('value')); // call your refreshGrid function with the value contained in the 'data-value' attribute
});

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...