Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/446.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 将jQuery添加到js代码中_Javascript_Jquery - Fatal编程技术网

Javascript 将jQuery添加到js代码中

Javascript 将jQuery添加到js代码中,javascript,jquery,Javascript,Jquery,我想用jQuery来做这个声明,但不能很好地实现它。在此声明中,我单击html中的图像并将其更改为新图像(img/HeaderImg2.jpg),请帮助 var imageButton = document.getElementById('headerImg'); imageButton.addEventListener('click', function(e) { console.log(e); imageButton.src ='img/HeaderImg2.jpg'

我想用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

$('#headerImg').on('click',function(e) {
    console.log(e);
    $(this).attr('src','img/HeaderImg2.jpg');
});
顺便说一句,如果你能做到这一点,最好使用普通javascript而不是jQuery

$('#headerImg').on('click',function(e) {
    console.log(e);
    $(this).attr('src','img/HeaderImg2.jpg');
});
顺便说一句,如果你能做到这一点,最好使用普通javascript而不是jQuery

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

顺便说一句,如果你能做到这一点,最好使用香草javascript而不是jQuery。

如果jQuery已经在使用香草javascript,为什么要切换到jQuery?如果jQuery没有坏,就不要修复它。@ElliotBonneville也许他想了解更多关于jQuery的信息。我知道如果javascript可以工作,那么就保留它,但我正在尝试学习jQuery及其功能。如果已经可以使用普通javascript,为什么要切换到jQuery?如果jQuery没有坏,就不要修复它。@ElliotBonneville也许他想了解更多关于jQuery的信息。我知道如果javascript可以工作,那么就保留它,但我正在尝试学习jQuery及其功能。如果已经可以使用普通javascript,为什么要切换到jQuery?如果jQuery没有坏,就不要修复它。@ElliotBonneville也许他想了解更多关于jQuery的信息。我知道如果javascript可以工作,那么就保留它,但我正在尝试学习jQuery及其功能。如果已经可以使用普通javascript,为什么要切换到jQuery?如果没有坏,就不要修复它。@ElliotBonneville也许他想了解更多关于jQuery的信息。我理解如果javascript可以工作,那么就保留它,但我正在努力学习jQuery及其功能。谢谢你,这非常有帮助。如果我想在单击同一个图像时也更改标题,我会怎么做?现在我正在使用childnodes。var pageTitle=document.getElementById('header');imageButton.addEventListener('click',函数(e){console.log(header.childNodes);header.childNodes[1].innerHTML=“Hello”},false);您可以尝试使用:
$('#header').find(':eq(1)').html('Hello')如果您能够使用jQuery,那么最好使用普通javascript,而不是jQuery。我想说,这取决于,如果我已经包含jQuery库,那么我会在普通JS上使用它,但不会仅仅为了它而包含它。在整个项目中也要保持一致。谢谢你,这非常有帮助。如果我想在单击同一个图像时也更改标题,我会怎么做?现在我正在使用childnodes。var pageTitle=document.getElementById('header');imageButton.addEventListener('click',函数(e){console.log(header.childNodes);header.childNodes[1].innerHTML=“Hello”},false);您可以尝试使用:
$('#header').find(':eq(1)').html('Hello')如果您能够使用jQuery,那么最好使用普通javascript,而不是jQuery。我想说,这取决于,如果我已经包含jQuery库,那么我会在普通JS上使用它,但不会仅仅为了它而包含它。在整个项目中也要保持一致。谢谢你,这非常有帮助。如果我想在单击同一个图像时也更改标题,我会怎么做?现在我正在使用childnodes。var pageTitle=document.getElementById('header');imageButton.addEventListener('click',函数(e){console.log(header.childNodes);header.childNodes[1].innerHTML=“Hello”},false);您可以尝试使用:
$('#header').find(':eq(1)').html('Hello')如果您能够使用jQuery,那么最好使用普通javascript,而不是jQuery。我想说,这取决于,如果我已经包含jQuery库,那么我会在普通JS上使用它,但不会仅仅为了它而包含它。在整个项目中也要保持一致。谢谢你,这非常有帮助。如果我想在单击同一个图像时也更改标题,我会怎么做?现在我正在使用childnodes。var pageTitle=document.getElementById('header');imageButton.addEventListener('click',函数(e){console.log(header.childNodes);header.childNodes[1].innerHTML=“Hello”},false);您可以尝试使用:
$('#header').find(':eq(1)').html('Hello')如果您能够使用jQuery,那么最好使用普通javascript,而不是jQuery。我想说,这取决于,如果我已经包含jQuery库,那么我会在普通JS上使用它,但不会仅仅为了它而包含它。在整个项目中也要保持一致。