ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
~~~ <title>Document</title> </head> <body> <div id="test"> hello world </div> <script> var test = document.getElementById("test"); test.onclick = function(){ /* this指执行事件的当前对象 */ // this.style.color ="red"; // this.innerHTML = "change" // if(this.style.color=="red"){ // this.style.color="#333" // }else{ // this.style.color="red" // } this.style.color=(this.style.color==="red")?"#333":"red"; } </script> </body> ~~~