admin管理员组文章数量:1400336
I have an jsp page with html and js like below. Now I want to keep the js function test() to another js file. I m trying to write that using jquery.
<div class="class1">
<a href="javascript:void(0)" onclick="test();" id="add_another" ><b>Add another user</b></a>
</div>
JS function
function test(){
alert("I am here");
//other code
}
I tried to write like this
$(function() {
$('#add_another').click(test);
});
But its not working. I am not sure if its because its having href="javascript:void(0)" When the user clicks Add Another User link, it show display another div. That is the test() doing. But the alert itself is not ing. Can somebody please help me in this?
I have an jsp page with html and js like below. Now I want to keep the js function test() to another js file. I m trying to write that using jquery.
<div class="class1">
<a href="javascript:void(0)" onclick="test();" id="add_another" ><b>Add another user</b></a>
</div>
JS function
function test(){
alert("I am here");
//other code
}
I tried to write like this
$(function() {
$('#add_another').click(test);
});
But its not working. I am not sure if its because its having href="javascript:void(0)" When the user clicks Add Another User link, it show display another div. That is the test() doing. But the alert itself is not ing. Can somebody please help me in this?
Share Improve this question asked Nov 25, 2013 at 9:59 user1049057user1049057 4594 gold badges15 silver badges37 bronze badges 2-
Have you tried
javascript:;
instead ofjavascript:void(0)
? – fnkr Commented Nov 25, 2013 at 10:01 - 1 It's working for me. Please check jsfiddle/Ub6Fk – Ishan Jain Commented Nov 25, 2013 at 10:04
1 Answer
Reset to default 4To replicate javascript:void(0)
you can use event.preventDefault() in js like this.
$(function () {
$('#add_another').click(function (e) {
e.preventDefault();
test();
});
});
本文标签: javascriptvoid(0) in jqueryStack Overflow
版权声明:本文标题:javascript:void(0) in jquery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744140516a2592596.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论