Blogger Information
Blog 30
fans 0
comment 0
visits 23490
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
javascript文本替换
深海巨兽皮皮虾的博客
Original
924 people have browsed it

代码:

<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>


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post