avoid browser reset from onclick event (prototype)
I have few anchors with a click event:
$$('.someanchor').invoke('observe', 'click', somefunct开发者_开发百科ion );
When the anchor is clicked, the browser scrolls to top.
I tried to insert return false at the end of somefunction, but it still scrolls up.
Usually I would use something like:
Event.observe('somelement', 'click', somefunction, false);
But this doesnt work for a collection of elements. So how do I return false from a invoke statement?
In somefunction, add the following at the end of the function body (make sure e is the last argument, and is used for the Event object):
e.preventDefault();
"e.preventDefault()" prevents the anchor default behavior but not the event propagation (bubbling). I would use "Event.stop(event)" to neutralize both, just for being on the safe side.
加载中,请稍侯......
精彩评论