这里我有代码:
<div class="starright"><img src="images/stars1.png" width="30" height="30" /></div>
<div class="starright"><img src="images/stars1.png" width="30" height="30" /></div>
<div class="starright"><img src="images/stars1.png" width="30" height="30" /></div>
<div class="starright"><img src="images/stars1.png" width="30" height="30" /></div>
我想更改里面的 onClick 图像,但只是在单击的对象上?不是全部都有吗?我有问题,因为这是 css 中的类而不是 ID,这可能吗,也许像 onClick 这样?
已编辑。这很好用:
function change(element){
element.innerHTML = "[new inner HMTL]";
}
但是当第二次点击时如何将其恢复到第一个图像上?
最佳答案
在 jquery 中尝试以下代码:
$('.starright').click(function(){
var path1 = "insert a path";
var path2 = "insert another path";
var src = $(this).find ('img').attr('src');
if (src==path1){
$(this).find ('img').attr('src',path2);
}
else{
$(this).find ('img').attr('src',path1);
}
});
是你想要的吗?
关于javascript - 更改类上的元素内部 html?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13006252/