JS onClick return false and jQuery global .click

I'm debuging my library in someone elses code: Part of it it's vanilla JS and my library is wirtten in jQuery. It have tabs tabber.js (code from 2006) and it have tabs onclick event attached to DOM that call return false .

tabberObj.prototype.init = function(e)
{
    DOM_a = document.createElement("a") ;

    DOM_a.appendChild( document.createTextNode( t.headingText ) ) ;
    DOM_a.href = "javascript:void(null);" ;
    DOM_a.title = t.headingText ;
    DOM_a.onclick = this.navClick ;
    ...
};


tabberObj.prototype.navClick = function(event)
{
   ...
   return false;
};

Here is tab code where there's click handler (line 311 and 265).

in my library I have:

$(document).bind('click.terminal', function(e) {
    var sender = $(e.target);
    if (!sender.closest('.terminal').hasClass('terminal') &&
        settings.onBlur(self) !== false) {
        self.disable();
    }
});

will my code fire. Does return false in JS do same thing as in jQuery. Will replacing return false by event.preventDefault() will make my code to run?

From symptoms it look like my function was not executed. I've try to fetch whole app using wget but it didn't run.


...and it have tabs onclick event attached to DOM that call return false.

... will my code fire or return false will stopPropagate like jQuery does.

If you mean that the tabs have onclick attributes on them:

<div onclick="return someFunction();">...</div>

(note you need the return in the attribute), or that they get a handler assigned to the reflected property for that:

someElementReference.onclick = someFunction;

...then doing return false in that handler will prevent the default action of the click but will not stop propagation. More (on my blog): The story on return false

Note, though, that the order in which old DOM0-style handlers (like the above) are fired relative to DOM2-style handlers like the ones jQuery adds is undefined . Some browsers fire the DOM0 handlers first, then the DOM2 handlers; others do it the other way around. It doesn't really matter in your case since you're not doing anything to stop propagation (and in particular, nothing to stop immediate propagation to other handlers on the same element), but it still seemed worth calling out.

链接地址: http://www.djcxy.com/p/3296.html

上一篇: event.preventDefault阻止Ajax调用

下一篇: JS onClick返回false和jQuery全局.click