Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/418.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中的Change event.target src attr_Javascript_Jquery - Fatal编程技术网

JavaScript中的Change event.target src attr

JavaScript中的Change event.target src attr,javascript,jquery,Javascript,Jquery,单击图像时,我想使用event.target更改其src属性 我正在尝试使用下面的代码实现相同的功能,但它不起作用;我哪里做错了 $(“.sim行编辑img”)。单击(函数(){ 警报(“点击图像”); $(“event.target”).attr(“src”https://cdn.iconscout.com/icon/free/png-256/car-location-find-navigate-gps-location-29571.png"); }); 您应该使用$(this).attr

单击图像时,我想使用
event.target
更改其src属性

我正在尝试使用下面的代码实现相同的功能,但它不起作用;我哪里做错了

$(“.sim行编辑img”)。单击(函数(){
警报(“点击图像”);
$(“event.target”).attr(“src”https://cdn.iconscout.com/icon/free/png-256/car-location-find-navigate-gps-location-29571.png");
});

您应该使用
$(this).attr()
作为
$('event.target')
将不会为您提供有效的
jQuery
对象。使用
$(this)
将为您提供所单击元素的引用,然后您可以更改该元素的
src
属性

$(“.sim行编辑img”)。单击(函数(){
警报(“点击图像”);
$(this).attr(“src”https://cdn.iconscout.com/icon/free/png-256/car-location-find-navigate-gps-location-29571.png");
});

您应该使用
$(this).attr()
作为
$('event.target')
将不会为您提供有效的
jQuery
对象。使用
$(this)
将为您提供所单击元素的引用,然后您可以更改该元素的
src
属性

$(“.sim行编辑img”)。单击(函数(){
警报(“点击图像”);
$(this).attr(“src”https://cdn.iconscout.com/icon/free/png-256/car-location-find-navigate-gps-location-29571.png");
});

event.target
是一个对象,因此请从event.target中删除引号

$(“.sim行编辑img”)。单击(函数(){
警报(“点击图像”);
$(event.target).attr(“src”https://cdn.iconscout.com/icon/free/png-256/car-location-find-navigate-gps-location-29571.png");
});

event.target
是一个对象,因此请从event.target中删除引号

$(“.sim行编辑img”)。单击(函数(){
警报(“点击图像”);
$(event.target).attr(“src”https://cdn.iconscout.com/icon/free/png-256/car-location-find-navigate-gps-location-29571.png");
});


让我更新我的问题,我需要event.target的原因实际上是我右键单击图像,出现关联菜单,然后在关联菜单上单击“编辑”并创建表单appears@user2828442如果答案对您有帮助,您可以勾选标记。让我更新我的问题,我需要事件的原因。目标实际上是我右键单击图像,出现关联菜单,然后在关联菜单上单击“编辑”并创建一个表单appears@user2828442如果答案对你有帮助,你可以在上面打勾。