如果我有10个图片,我需要做鼠标对,鼠标出来,并使用点击改变图像和在第二次点击返回回来,,但没有任何特殊的id任何图像?你能帮忙吗!
发布于 2015-12-25 04:25:51
你可以用“这个”选择器
$('img').hover(function(){
// Code to do when is mouse over (Mouse Enter)
$(this).attr("src", urlImage);
},function(){
// Code to do (Mouse Leave)
$(this).attr("src", AnotherUrlImage);
});这是单击切换图像的正确脚本。
$("img").one("click", click1);
function click1() {
$(this).attr("src", "URLIMAGE2");
$(this).one("click", click2);
}
function click2() {
$(this).attr("src", "URLIMAGE2");
$(this).one("click", click1);
}发布于 2015-12-25 02:28:16
在jQuery中,可以使用以下选择器向每个<img>添加一个函数:
$('img').onclick(function(){
//Some code
});发布于 2015-12-25 04:47:19
您可以在单击图像时使用.toggle()进行此操作。
$('img').toggle(function() {
$(this).attr("src", BackImage);
}, function() {
$(this).attr("src", FrontImage);
});https://stackoverflow.com/questions/34459463
复制相似问题