我正在尝试在单击此 anchor 标记时发送标签的值。任何人都可以建议我传递标签值的最佳方法是什么(标签值动态变化,因此希望在单击 anchor 标记时传递该值到java脚本函数。)
示例代码:
<a class="k-link" onclick="Getvalue("$("#ID").html()">Profile</a>
2
function Getvalue(Id) {
}
最佳答案
jQuery
$("a").on("click", function(){
alert($(this).text());
})
<强> EXAMPLE
因为我们通过 jQuery 绑定(bind)点击事件,所以您不需要内联执行此操作。您的 HTML 将变为:
<a class="k-link">Profile</a>
Unlike the .html() method, .text() can be used in both XML and HTML documents. The result of the .text() method is a string containing the combined text of all matched elements. (Due to variations in the HTML parsers in different browsers, the text returned may vary in newlines and other white space.)
关于javascript - 如何在 onclick 事件上发送标签的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12916492/