Under normal circumstances, I add jacascript to the href of a tag:; You can block its click events.
But this time I got a function and I can't modify the href inside. Because I need an href address to do Ajax loading.
How can I set this href to perform the onclick event without jumping?
Reply content:
Under normal circumstances, I add jacascript to the href of a tag:; You can block its click events.
But this time I got a function and I can't modify the href inside. Because I need an href address to do Ajax loading.
How can I set this href to perform the onclick event without jumping?
var _this = $(this); var subHref = _this.attr('href'); e.preventDefault(); $.ajax({ url: '1.html', data: formVal, type: post, dataType: 'json', success: function(res) { if (res.code == 200) { location.href = subHref; } else { } } error: function() { } });
href= "javascript:;" onclick= "MyFunction (" http://shabi.com ")"
This is not going to work, the address must be written in the href?
Do the function parameter passing.
$ ("a"). On ("click", Function () {
return false;//想干嘛,干嘛
})
JS has a function to block the default behavior
E.preventdefault ();
You can try it.
In fact, clicking on the a tag jumps, because clicking on the triggered function returns true by default, so when the return value of the OnClick function is modified to false, it will not jump.
var a=document.getElementById("a_id");a.onclick=function(e){//do something for myselfreturn false;}
The execution function writes only return and can not execute
var a=document.getElementById("a_id");a.onclick=function(e){return;}
In the Click event, directly
return false;
Can