🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
### **jQuery基础知识篇之小图片切换** #### **HTML的代码如下所示:** ~~~ <div class="niming"> <img src="img/no.png" onclick="changImg()" id="changimg"> <span>匿名评价</span> </div> ~~~ ###** css代码如下所示:** ~~~ /*匿名评价*/ .niming { position: relative; width: 100%; height: 30px; padding-left: 10px; } .niming #changimg { position: absolute; top: 0; left: 10px; margin-top: 6px; width: 18px; line-height: 30px;; } .niming img+span { position: absolute; top: 0; left: 35px; display: inline-block; height: 30px; line-height: 30px; } ~~~ jQuery的代码如下所示: ~~~ function changImg() { var imgObj = document.getElementById("changimg"); if(imgObj.getAttribute("src",2)== "img/no.png") { imgObj.src = "img/yes.png"; }else { imgObj.src = "img/no.png"; } } ~~~