jquery attr(“onClick”) - ie and ff

后端 未结 5 772
长情又很酷
长情又很酷 2021-01-13 01:12

Using jquery, I\'d like to get the javascript from an A tag\'s onClick attribute.


In Fir

相关标签:
5条回答
  • 2021-01-13 01:57

    Browser safe :

    jQuery('a')[0].getAttribute('onclick');
    
    0 讨论(0)
  • 2021-01-13 02:00

    Internet Explorer <8 has a completely broken implementation of setAttribute and getAttribute which deal with the property with the given name instead of the attribute.

    I'm not aware of a work around.

    0 讨论(0)
  • 2021-01-13 02:08

    How can I retrieve just the javascript, and not the wrapped function, in IE 6/7

    You generally don't want to rely on string values for inline event handlers at all (in fact you should generally avoid using inline event handler attributes altogether in favour of binding to functions from script — especially if you're using jQuery, where this approach is the norm). But if you have to, the workaround is the DOM method getAttributeNode.

    var link= $('a')[0]; // or whatever
    alert(link.getAttributeNode('onclick').value);
    
    0 讨论(0)
  • 2021-01-13 02:08

    Have you tried :

    alert($('a').attr("onclick"))
    

    In XHTML onClick is not the right version.

    0 讨论(0)
  • 2021-01-13 02:10

    Better than adding onclick attribute is behalf of IE6 / IE7 this solution:

    $("a").click(function () { .. anything to do .. })
    
    0 讨论(0)
提交回复
热议问题