[removed] get element's current “onclick” contents

前端 未结 3 1136
暖寄归人
暖寄归人 2020-12-17 10:45

I have a page with the following code:

link

I need to actually rea

相关标签:
3条回答
  • 2020-12-17 10:48

    You can use Javascript on anchor tag like:

    <script type="text/javascript">
    
      function testClick(id)
      {
         alert(id);
      }
    
    </script>
    
    <a href="#" id="test" onclick="testclick(this.id);">Click</a>
    
    0 讨论(0)
  • 2020-12-17 10:51

    Assuming the tag is well-formed, a tag's attribute can be obtained via Element.getAttribute.

    document.getElementById('test').getAttribute('onclick')
    // -> "somefunction"
    

    Hopefully you aren't using onclick for some unscrupulous purpose like storing data.

    0 讨论(0)
  • 2020-12-17 11:04

    You should try:

    document.getElementById('test').onclick.toString()
    
    0 讨论(0)
提交回复
热议问题