gpt4 book ai didi

javascript - 将 jQuery 添加到 js 代码中

转载 作者:行者123 更新时间:2023-11-28 20:02:44 24 4
gpt4 key购买 nike

我想使用 jQuery 来做出这个声明,但无法完全让它工作。在此声明中,我单击 html 中的图像并将其更改为新图像 (img/HeaderImg2.jpg) 请帮忙。

  var imageButton = document.getElementById('headerImg');
imageButton.addEventListener('click', function(e)
{
console.log(e);
imageButton.src ='img/HeaderImg2.jpg';
} ,false);

最佳答案

试试这个:

$('#headerImg').on('click',function(e) {
console.log(e);
$(this).attr('src','img/HeaderImg2.jpg');
});

顺便说一句,如果可以的话,最好使用普通 javascript,而不是使用 jQuery。

关于javascript - 将 jQuery 添加到 js 代码中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21372363/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com