当页面成功加载时,您需要这样做。试试这个
fiddle
相反
<script>
window.onload = convert;
function convert() {
if (navigator.userAgent.match(/Android/i) ||
navigator.userAgent.match(/webOS/i) ||
navigator.userAgent.match(/iPhone/i) ||
navigator.userAgent.match(/iPad/i) ||
navigator.userAgent.match(/iPod/i) ||
navigator.userAgent.match(/BlackBerry/) ||
navigator.userAgent.match(/Windows Phone/i) ||
navigator.userAgent.match(/ZuneWP7/i))
{
var url4 = "http://news.ycombinator.com";
} else {
var url4 = "lol.png";
}
document.getElementById("link").src=url4;
//convert();
}
</script>