ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
## **如何实现一个事件绑定(监听)** ``` <ul> <li>1</li> <li>2</li> <li>3</li> <li>4</li> </ul> <script> var lis = document.getElementsByTagName('li'); for(let i = 0;i<lis.length;i++){ lis[i].onclick=function(){ console.log(this.innerHTML) } } </script> ``` jquery: ``` <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script> <ul> <li>1</li> <li>2</li> <li>3</li> <li>4</li> </ul> <script> $('li').click(function(){ console.log($(this).text()) }) </script> ```