锚文本Call function on mouse click or Enter keypress

锚文本Call function on mouse click or Enter keypress
 点击下载

Typically useful on anchor elements for which following the link should produce javascript functionality instead of the default action (following the URL).

Function binds mouse click and enter keypress to a specified element, and calls the specified function. The default action (e.g. following the href for an anchor) is prevented.

Release 1.2+ supports binding to more than one element, because the callback function is aware of the target of the click / enter keypress.

Usage:

  1. $.clickOrEnter(yourElement,yourFunction); 

e.g.

  1. $.clickOrEnter('a',popup); 

This essentially replaces the style of

  1. <a href="javascript:function();">Foo</a> 
  2. <a href="foo.html" onclick="function();" onkeypress="function();">Bar</a> 

which are inaccessible / obtrusive.

转载请注明:代码家园 » 锚文本Call function on mouse click or Enter keypress

评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)