Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.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中更改imgsrc_Javascript_Jquery_Html_Css - Fatal编程技术网

Javascript 在jQuery中更改imgsrc

Javascript 在jQuery中更改imgsrc,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我希望在用户向下滚动页面后更改图像(图像大小相同,但颜色不同): HTML <ul class="social-media-nav-center"> <li> <a href="https://twitter.com/" target="_blank"><img id="twitter" class="small" src="path/to/image-icon.png" /> </a> </li>

我希望在用户向下滚动页面后更改图像(图像大小相同,但颜色不同):

HTML

<ul class="social-media-nav-center">
  <li>
    <a href="https://twitter.com/" target="_blank"><img id="twitter" class="small" src="path/to/image-icon.png" /> 
    </a>
  </li>
</ul>
当我向下滚动页面时,图像无法识别,它只是一个问号

注意

图像路径是有效的,相信我

-

我觉得这是一个非常简单的解决方案,有什么想法吗?

试试这个

var path='path/to/image-color-icon.png'
$("#twitter").attr("src", path);
核对

HTML

CSS


可能是因为路径无效?检查网络选项卡中的错误。为什么在HTML没有的情况下,JS src中的
。/
?您是否意识到src是基于html文件位置,而不是JS文件位置?在
控制台
选项卡中,请验证是否存在错误,在这种情况下,禁止访问图像。如果您使用linux或Mac,请尝试
chmod
您的目录。这是我的错误。我给了它正确的道路。我再也不用Adobe括号了。很抱歉给大家带来不便。这是这个问题最好的部分:“图像路径是有效的,相信我。”!!!这和正在讨论的事情是一样的。这有什么新鲜事吗?我会标记为正确,因为我的文本编辑器欺骗了我。它所说的正确路径实际上是错误的。这是我的错误。我给了它一条正确的道路。OP已经接受了这个答案,怎么会有人否决这个答案呢。投反对票的人请在投反对票前发表评论。这将帮助人们纠正或改进提供的解决方案。
var path='path/to/image-color-icon.png'
$("#twitter").attr("src", path);
<ul class="social-media-nav-center">
  <li>
    <a href="https://twitter.com/" target="_blank"><img id="twitter" class="small" src="https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcRgdlWvqZIB0r6qkjFS_t9uMKD9gQIVMV3fE-Vw9BMoRfNEmJG2" /> 
    </a>
  </li>
</ul>
$(document).ready(function(){
  $(window).scroll(function(){      
    if($(window).scrollTop() > $(window).height()) {
      $("#twitter").attr("src", "http://www.planwallpaper.com/static/images/744081-background-wallpaper.jpg");
    }
  })
})
.social-media-nav-center{height:1000px;}