I am trying to change the URL of an image by JavaScript where if it is a mobile it will show this image https://axxelfinance.com/hello1.jpg
or if it is a desktop it will show this image https://axxelfinance.com/hello2.png
但是我不知道怎么了,这是行不通的。请帮我。
谢谢。
if (/iPhone|iPad|iPod|Android/i.test(navigator.userAgent)) {
document.getElementById('img1').src = 'https://axxelfinance.com/hello1.jpg';
document.getElementById('img1').style.height = '200px';
document.getElementById('img1').style.width = '250px';
} else {
document.getElementById('img1').src = 'https://axxelfinance.com/hello2.png';
document.getElementById('img1').style.height = '300px';
document.getElementById('img1').style.width = '200px';
}
<div class="container">
<center>
<img id="img1" src="https://axxelfinance.com/hello1.jpg" height="200px" width="250px">
</center>
</div>