Last active
May 23, 2019 06:43
-
-
Save Rainbowrain-TW/41a050467d8e5682dca52bc9e8ad5854 to your computer and use it in GitHub Desktop.
Vanilla JS eventlistener example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//1 | |
document.getElementById('myDiv').addEventListener('click', function(){alert('clicked')}) | |
//2 | |
document.getElementById('myDiv').onclick = ()=>{alert('clicked')} | |
//3 | |
<div id='myDiv' onclick='myDivClick'>按我</div> | |
function myDivClick(){ | |
alert('clicked') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment