對屬性進行操作
阿新 • • 發佈:2018-11-03
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>對樣式進行操作</title> <script type="text/javascript"> function imageChange(img) { document.getElementById("src1").setAttribute("src", img); } function getImageURL() { var i = document.getElementById("src1").getAttribute("src"); alert(i); } </script> </head> <body> <!--對屬性進行操作--> <img src="" id="src1" /><br /> <input type="button" value="獲取當前圖片的地址" onclick="getImageURL()" /> <input type="button" id="btn1" class="btn" value="1" onclick="imageChange('img/1.jpg')" /> <input type="button" id="btn2" class="btn" value="2" onclick="imageChange('img/2.jpg')" /> <input type="button" id="btn3" class="btn" value="3" onclick="imageChange('img/3.jpg')" /> <input type="button" id="btn4" class="btn" value="4" onclick="imageChange('img/4.jpg')" /> </body> </html>