jQuery和JavaScript onmouseover兼容性

问题描述 投票:0回答:1

我创建了一个eBay列表,它在eBay上正常工作。

但我有一个问题。该列表通过第三方软件列出,该软件有自己的JS用于更改图像。它不适用于我的脚本。我使用jQuery。

任何人都可以建议一个简单的方法来交换点击事件上的图像src?

例如:保持原样,但覆盖JS。现在它被设置为侦听鼠标悬停。我可以写一个新的脚本,所以当点击它会交换图像?

这是列表的链接:Listing template here

javascript jquery ebay
1个回答
0
投票

要更改图像的src属性:

$('#myImage').click(function(){
    $(this).attr('src', 'myNewImage.jpg');
});

要停止收听鼠标悬停事件:

$('#myTargetWhichHasAnEventAttached').off('mouseover');

编辑以回答评论:

$('.image_small_js').off('mouseover'); // supposed that the mouseover event is attached on .image_small_js

$('.image_small_js').click(function(){
    $('#bigpicture').attr('src', $(this).attr('src')).hide().show(); // .hide().show() makes the change effect more smoothy... can be used with timers
});
© www.soinside.com 2019 - 2024. All rights reserved.