Under normal circumstances, I can add jacascript:; to the href of the a tag to prevent its click event. But this time I got a function and I cannot modify the href in it. Because I need the href address for ajax loading. How can I set this to enable this href to execute the onclick event without adding jacascript:; to the href of the a tag, I can prevent its click event.
But this time I got a function, and I cannot modify the href in it. Because I need the href address for ajax loading.
How can I configure this href to execute the onclick event without redirecting?
Reply content:
Under normal circumstances, I add jacascript:; to the href of a tag to prevent its click events.
But this time I got a function, and I cannot modify the href in it. Because I need the href address for ajax loading.
How can I configure this href to execute the onclick event without redirecting?
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 the case. Do I have to write the address in href?
Pass function parameters
$ ("A"). on ("click", function (){
Return false; // What do you want?
})
Js has a function to prevent default behavior.
E. preventDefault ();
You can try it.
In fact, clicking the tag will jump, because the function triggered by clicking returns true by default, so when the onclick function returns false, it will not jump.
var a=document.getElementById("a_id");a.onclick=function(e){//do something for myselfreturn false;}
The execution function can only write return or not execute
var a=document.getElementById("a_id");a.onclick=function(e){return;}
In the click event
return false;
You can.