如何通过javascript或jscript执行锚标记的click事件? [英] How to execute click event of an anchor tag by javascript or jscript ?
问题描述
我想通过javascript或jscript执行锚标记的click事件。
有什么办法吗?
我尝试了每一个代码,但它似乎无法正常工作。
这是我的html代码:
I want to execute click event of an anchor tag by javascript or jscript.
Is there any way to do ?
i tried with every code but it seems to be not working.
Here is my html code:
<br />
<html xmlns="http://www.w3.org/1999/xhtml"><br />
<head runat="server"><br />
<title></title><br />
<script type="text/javascript"><br />
function dothis() {<br />
alert('I want this');<br />
document.getElementById('about').click();<br />
<br />
}<br />
</script></pre><br />
<br />
<body><br />
<form id="form1" runat="server"><br />
<a href="AboutUs.aspx" name="about" id="about" >click here</a><br />
</form><br />
</body><br />
</html><br />
Javascript代码:
函数dothis(){
alert('我想要这个');
document.getElementById('about')。click();
}
和以上javascript代码在C#中加载页面时正在执行...#b $ b我能够在页面加载时执行函数dothis()
并显示警告msg但不执行锚标记的click事件..我需要帮助
预先感谢您的帮助
Javascript code:
function dothis() {
alert('I want this');
document.getElementById('about').click();
}
and this above javascript code is getting executed while page load in C#
I am able to execute function dothis() on page load
and alert msg gets displayed but click event of anchor tag is not executed ..there i need help
Thanks in advance for help
推荐答案
亲爱的,
这里我已经粘贴了实现目标的代码。
为此,我们需要将jQuery库文件包含在HTML中。
Ex: -
Hi dear,
Here i have pasted the code for achieving your goal.
For this we need to include the jQuery library file to out HTML.
Ex :-
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="jquery-2.0.3.js"></script>
<script type="text/javascript">
( function (){
dothis();
});
function dothis(){
alert(' 我想要这个');
(function () { dothis(); }); function dothis() { alert('I want this');
(' #about')[ 0 ]。click();
}
< / 脚本 >
< / head >
< 正文 >
< form id = form1 runat = server < span class =code-keyword>>
< di v >
< a href = AboutUs.aspx id = about > 点击此处< / a >
< / div >
< / form >
< / body >
< / html >
('#about')[0].click(); } </script> </head> <body> <form id="form1" runat="server"> <div> <a href="AboutUs.aspx" id="about">click here</a> </div> </form> </body> </html>
希望这对您有所帮助,请看看它让我知道如果它适合你。
如果需要,我可以在这方面为你提供更多帮助。
Hoping this will be of help to you, please have a look into it let me know if it worked for you.
So that i can help you more on this regard if required.
这篇关于如何通过javascript或jscript执行锚标记的click事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!