代码:
<div class=""> //demo(this)传递当前对象 <a href="../image/p1.png" title="图一" onclick="demo(this); return false;">1</a> <a href="../image/p2.png" title="图二" onclick="demo(this); return false;">2</a> <a href="../image/p3.png" title="图三" onclick="demo(this); return false;">3</a> <img src="../image/p4.png" alt="" id="img"> <p id="p">没图</p> </div> <script> function demo(fa){ //获取当前href值 var img = fa.href; //获取title值 var text = fa.title; //获取占位符 var imag = document.getElementById('img'); var txt = document.getElementById('p'); //替换 imag.src = img; txt.innerHTML = text; } </script>