javascript:void(0) in jquery
javascript:void(0) in jquery
我有一个包含html和js的jsp页面,如下所示。现在我想将js函数test()保存到另一个js文件中。我正试着用jquery来写。
<div class="class1">
<a href="javascript:void(0)" onclick="test();" id="add_another" ><b>Add another user</b></a>
</div>
JS函数
function test(){
alert("I am here");
//other code
}
我试着这样写
$(function() {
$('#add_another').click(test);
});
但它不起作用。我不确定是否是因为它有href="javascript:void(0)"当用户单击Add Another user链接时,它会显示另一个div。这就是test()所做的操作。但警报本身并没有到来。有人能帮我吗?
要复制javascript:void(0)
,可以像这样在js中使用event.prventDefault()。
$(function () {
$('#add_another').click(function (e) {
e.preventDefault();
test();
});
});
相关文章:
- grep in JQuery to C#
- jQuery, Javascript : Javascript wrap in jQuery(), $() - 这是什么
- javascript in jquery popup
- 启用和禁用基于even-in-jQuery的Span类
- setTimeout in jQuery with a loop
- javascript:void(0) in jquery
- Post/Get handler in Jquery/Javascript
- :not and :first in jquery
- 在函数下使用 &&in jquery if 条件
- setDate in jQuery UI DatePicker
- Passing eventobejct in jquery
- AJAX 请求混淆 in jQuery.
- jquery mobile login parse json response in jquery mobile
- .submit in javascript vs .submit in jquery
- event.srcElement.value equivalent in jQuery
- Html in jquery string
- this.something outside each in jquery
- AJAX in jquery 不起作用
- position() in jquery ui
- $(this) vs e.target or event.target in jquery