使用jQuery:
$("*[src]").attr("src", "http://example.com/somerandomimage.jpg?foo=bar");
如果你打算只更換某些網址,限制了選擇:具有在首位的HTML字符串時
$("*[src='http://example.com/somerandomimage.jpg']").attr("src", "http://example.com/somerandomimage.jpg?foo=bar");
相同的操作:
$("*[src='http://example.com/somerandomimage.jpg']", $(<html snippet>)).attr("src", "http://example.com/somerandomimage.jpg?foo=bar");
<html snippet>
應該是格式良好的並且植根於單個元件。
強制單個根如下:
$("*[src='http://example.com/somerandomimage.jpg']", $(<html snippet>).wrapAll("<div/>").first().parent()).attr("src", "http://example.com/somerandomimage.jpg?foo=bar");
注遍歷到生成的根作爲wrapAll
返回原始jQuery對象。
在運行時的建造時間 –
對不起......在JavaScript ... – richard
,這可能意味着前端,後端,建設等 –