如何使用jquery更改包含Parent标签的图像src?
请告诉我如何使用c#检索相同内容?
C#代码:
string s;
s= "<span id=\"span1\"><table><tr><td><img src=\"/image/img01.jpg\"></td></tr>";
I have formatted above code to string and assigned to one label
label1.text=s.tostring();
现在我想使用jquery更改img src。
我是jquery的新手请任何人帮我解决这个问题。 *注意:我不想为img标签使用id属性。
答案 0 :(得分:1)
如果您在跨度内只有一个图像(如您的示例):
$('#span1 img').attr('src','img02.jpg');
答案 1 :(得分:0)
$('#span1 img').attr('src', '/path/to/new/img.jpg');
这应该适合你。
编辑 - 在2分钟内击败拳头!
答案 2 :(得分:0)
有两个简单的选项,首先使用“andy”
给出的代码$('#span1 img').attr('src','img02.jpg');
或
<img src=\"/image/img01.jpg\" id="exampleimg">
$('#exampleimg').attr('src','img02.jpg');