How to change onclick using javascript?
问题 How to change onclick using javascript ? https://jsfiddle.net/749rt0m7/1/ I tried to use this code, but not work. How can i do ? <span onclick="test_fn('aaa,bbb')" id="xx">edit</span> <script> document.getElementById('xx').onclick = "test_fn(111,222)"; </script> 回答1: There are a couple things going on here. First of all test_fn() is not a function in your jsfiddle. You will need to define it in order for it to be called. Second of all you are setting the onclick attribute to be a string not a