将onclick事件添加到超链接 [英] Add onclick event to hyperlink
问题描述
我有一个包含我的html内容的字符串在代码后面这样的链接
I have a string containing my html content in code behind link like this
<p><a href=\"http://www.google.com\">rrr</a></p>"
1.我需要在此链接中添加一个onclick事件。
1.I need to add a onclick event to this link.
2.需要获取href值。
2.Need to get the href value.
我没有链接的id或类,因此无法使用Javascript直接访问它。我是Jquery的新手。有点卡在这里。我怎么能实现这个目标?
I dont have a id or class for the link so cant access it directly using Javascript. I am a newbie to Jquery. Kinda stuck in here. How can I achieve this ?
我试图通过防止默认功能使用Javascript onclick解决方案,但我的HTML内容是在RUNTIME生成的。所以无论我在document.ready中写什么似乎都没有用。
I tried using the Javascript onclick solutions by preventing default functionality, but MY HTML CONTENT IS GENERATED AT RUNTIME. So whatever I write in document.ready doesnt seem to work at all.
推荐答案
Jquery与工作jsbin - http://jsbin.com/azOSayA/1/edit
Jquery with working jsbin - http://jsbin.com/azOSayA/1/edit
$("a").click(function(e){
var a_href = $(this).attr('href');
e.preventDefault();
});
这篇关于将onclick事件添加到超链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!