Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/445.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 一张图片上的Onclick、onmouseover、onmouseout_Javascript_Jquery_Html - Fatal编程技术网

Javascript 一张图片上的Onclick、onmouseover、onmouseout

Javascript 一张图片上的Onclick、onmouseover、onmouseout,javascript,jquery,html,Javascript,Jquery,Html,如果我有10个图像,我需要在鼠标悬停、鼠标悬停和使用鼠标单击来更改图像,然后在第二次单击返回时,但没有任何图像的特殊id??你能帮忙吗 在jQuery中,您可以使用此选择器向每个添加一个函数: $('img').onclick(function(){ //Some code }); 在jQuery中,您可以使用此选择器向每个添加一个函数: $('img').onclick(function(){ //Some code }); 您可以使用“this”选择器 $('img').

如果我有10个图像,我需要在鼠标悬停、鼠标悬停和使用鼠标单击来更改图像,然后在第二次单击返回时,但没有任何图像的特殊id??你能帮忙吗

在jQuery中,您可以使用此选择器向每个
添加一个函数:

$('img').onclick(function(){
    //Some code
});

在jQuery中,您可以使用此选择器向每个
添加一个函数:

$('img').onclick(function(){
    //Some code
});

您可以使用“this”选择器

$('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);
}

您可以使用“this”选择器

$('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);
}
您可以使用
.toggle()
在单击图像时执行此操作

$('img').toggle(function() {
    $(this).attr("src", BackImage);
    }, function() {
      $(this).attr("src", FrontImage);
});
您可以使用
.toggle()
在单击图像时执行此操作

$('img').toggle(function() {
    $(this).attr("src", BackImage);
    }, function() {
      $(this).attr("src", FrontImage);
});

Java标记已删除,因为我看不出此问题与此语言有多大关系。您好,欢迎使用SO…您应该了解此处的问题类型使用此链接。。。。。一旦您尝试了一些代码并需要帮助调试,社区将帮助您……:DJava标记已删除,因为我看不出此问题与此语言有多大关系。您好,欢迎访问SO……您应该了解此处的问题类型使用此链接。。。。。一旦您尝试了一些代码并需要帮助调试,社区将帮助您……:将处理程序切换到DPassing是一个好主意,似乎是解决此问题的一个非常优雅的方法。您好:)首先,我想感谢您的回答,但我有一个问题,当我将切换脚本放入图像解压器时,你能告诉我为什么吗?是的,我尝试了这个功能,也许不是更好的。我用经过测试的脚本编辑了我的答案。:)hello viceente:)悬停脚本与单击脚本不兼容。有什么建议吗?将处理程序传递给toggle是一个好主意,似乎是解决此问题的一个非常优雅的方法。您好:)首先,我想感谢您的回答,,但我有一个问题,当我将toggle脚本设置为images dissapper时,您能告诉我为什么吗?是的,我尝试使用此函数,可能不是更好的方法。我用经过测试的脚本编辑了我的答案。:)hello viceente:)悬停脚本与单击脚本不兼容。有什么建议吗?