-
摇曳的蔷薇
<!DOCTYPE html><html><head> <meta charset="UTF-8"> <title></title></head><body><span class="test">demo1</span><span class="test">demo2</span><span class="test">demo3</span><span class="test">demo4</span><script src="jquery.js"></script><script> // js版 var aLi = document.querySelectorAll('.test'); for (var i = 0; i < aLi.length; i++) { aLi[i].addEventListener('click', function(){ this.style.color='red' }); } // jquery版本 $(".test").on('click', function(){ $(this).css('color', 'red'); }); </script></body></html>
-
一只萌萌小番薯
<p onclick="this.style.color='#f00'">demo</p>
-
慕丝7291255
<span id="demo">点击变色</span>//js$("#demo").on("click",function(){ $("#demo").css("color","red")})
-
互换的青春
<span id="demo">点击变色</span>//jsdocument.querySelector('#demo').onclick=function(){ document.querySelector('#demo').style.color='red'};
-
慕码人2483693
比较赞同楼上做法:$(span).on("click",function () {$(this).addClass("red")})