This article mainly shares with you JS hyperlinks to dynamically display images. It is mainly shared with you in the form of code. I hope it can help everyone.
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> <meta charset="utf-8" /> <script> onload = function () { var al = document.getElementById('al'); al.onmouseover = function () { if (document.getElementById('dv')) { document.body.removeChild(document.getElementById('dv')); //防止重复添加 } var dvObj = document.createElement('p'); dvObj.id = 'dv'; var imgObj = document.createElement('img'); imgObj.src = '2.jpg'; imgObj.width = '200';//不可以加px imgObj.height = '200'; dvObj.appendChild(imgObj); dvObj.style.position = 'absolute'; dvObj.style.left = this.offsetLeft + 'px'; dvObj.style.top = this.offsetTop + this.offsetHeight + 'px'; document.body.appendChild(dvObj); } al.onmouseout = function () { if (document.getElementById('dv')) { document.body.removeChild(document.getElementById('dv')); } } } </script> </head> <body> <a id="al" href="http://www.baidu.com">百度一下</a> <!--<img src="2.jpg" width="200" height="200"/>--> </body> </html>
Related recommendations:
Problems with dynamically displaying images in php
The above is the detailed content of JS hyperlink realizes dynamic display of pictures. For more information, please follow other related articles on the PHP Chinese website!