在超链接上调用javascript函数点击 [英] call javascript function on hyperlink click
本文介绍了在超链接上调用javascript函数点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在ASP.NET的c#代码隐藏文件中动态创建超链接。我需要在客户端点击时调用JavaScript函数。我怎么做到这一点?
I am dynamically creating a hyperlink in the c# code behind file of ASP.NET. I need to call a JavaScript function on client click. how do i accomplish this?
推荐答案
Neater仍然,而不是典型的href =#
或 href =javascript:void
或 href =whatever
,我想这个更有意义:
Neater still, instead of the typical href="#"
or href="javascript:void"
or href="whatever"
, I think this makes much more sense:
var el = document.getElementById('foo');
el.onclick = showFoo;
function showFoo() {
alert('I am foo!');
return false;
}
<a href="no-javascript.html" title="Get some foo!" id="foo">Show me some foo</a>
如果Javascript失败,会有一些反馈。此外,不稳定的行为(在 href =#
的情况下跳页,在 href =的情况下访问同一页面
)已被淘汰。
If Javascript fails, there is some feedback. Furthermore, erratic behavior (page jumping in the case of href="#"
, visiting the same page in the case of href=""
) is eliminated.
这篇关于在超链接上调用javascript函数点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文