怎样用js改变图片路径?

JavaScript038

怎样用js改变图片路径?,第1张

<script>

function aa(h)

{

if (h==1)

{document.all.img1.src="images/22.jpg"}

if (h==2)

{document.all.img1.src="images/5.jpg"}

}

</script>

<img src="images/5.jpg" onClick="aa(1)" id="img1">

<img src="images/22.jpg" onClick="aa(2)" id="img2">

var html = '<div class="main">文字文字文字<img src="/upload/123.jpg" /></div>'

var reg = /(<div[^>]*class[=\"\']+main[\"\']?[^>]*>(?:(?!<img)[\s\S])*<img[^>]*src[=\"\']+)(\/upload[^\"\']*[\"\']?[^>]*>(?:(?!<\/div>)[\s\S])*<\/div>)/gi

html = html.replace(reg, "$1http://www.abc.com$2")

console.log(html)