Javascript onclick

后端 未结 4 1841
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-16 14:42

I have code like

test

Later on code is added to the same anchor tag like

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-16 14:52

    You have a mistake in your statement:

    JAVASCRIPT

    lnk = document.getElementById('lnk1')
    lnk1.onclick = function() { do something} \\ replace lnk1 with lnk
    lnk.onclick = function() { do something} \\ this will work
    

    You have defined lnk as variable but your are calling lnk1 with onclick event. This is a wrong statement.

    USE HTML

    test
    

    See the Demo: http://jsfiddle.net/tm5cX/

提交回复
热议问题