jquery如何改变替换这个图片src的地址

<div id="pic"><img src="/images/newimages/" width="120" height="90" alt="" /></div>
<div id="pic"><img src="/images/newimages/1.jpg" width="120" height="90" alt="" /></div>
我想只改变第一个<img src="images/newimages/" width="120" height="90" alt="" />为<img src="images/newimages/noimage.jpg" width="120" height="90" alt="" />,第二个<img src="/images/newimages/1.jpg" width="120" height="90" alt="" />不改变。感谢各位大侠指导帮助写一下。

第1个回答  2015-03-02
<!DOCTYPE HTML>
<html>
<head>
<title>yugi</title>
<meta charset=UTF-8 />
<style type="text/css">
</style>
<script type="text/javascript" src="jquery-1.8.0.min.js"></script>
<script type="text/javascript">
    jQuery (function ($)
    {
     $("#pic:first img").attr ("src", "images/newimages/noimage.jpg");
    });
</script>
</head>
<body>
<div id="pic">
<img src="/images/newimages/" width="120" height="90" alt="" />
</div>
<div id="pic">
<img src="/images/newimages/1.jpg" width="120" height="90" alt="" />
</div>
</body>
</html>

追问

网站里有这种情况,html页面发现就替换为其他路径正常的不用替换,怎么写呢?大侠再指导一下

追答

$("img[src='/images/newimages/']").attr ("src", "images/newimages/noimage.jpg");

怎么你的需求变来变去的

我想只改变第一个为,第二个不改变

死脑残提问者,提这个问,还来追问我,结果却采纳别人,卑鄙无耻,自己脑残害别人

这个该死的提问者死J8,越想越气愤,真想一J8甩死你。。。

第2个回答  推荐于2016-09-01

试试

$("img[src='/images/newimages/']").attr('src','/images/newimages/noimage.jpg');

本回答被提问者采纳
相似回答