zoukankan      html  css  js  c++  java
  • 鼠标滑过、图片对应的文字高亮

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="UTF-8">
            <title></title>
        </head>
        <style>
            li{
                list-style: none;
                float: left;
                text-align: center;
            }
        </style>
        <body>
            <ul id="u">
                <!--<li><img src="a.jpg"/><p>小米</p></li>-->
            </ul>
        </body>
    </html>
    <script>
        var jsonObj = {
             "info":[
                        {"src":"01.jpg","name":"小米"},
                        {"src":"02.jpg","name":"大米"},
                        {"src":"03.jpg","name":"高粱米"}
                    ]
        }
        var oUl = document.getElementById("u");
        var str = "";
        for( var i = 0 ; i < jsonObj.info.length ; i++ ){
            var item = jsonObj.info[i];
            str += "<li><img src="+item.src+"/><p>"+item.name+"</p></li>"
        }
        oUl.innerHTML = str;
        var list = oUl.children;
        oUl.addEventListener( "mouseover",function( e ){
            var e = e || event;
            var target = e.target || e.srcElement;
            if( target.tagName.toLowerCase() == "img" ){
                target.style.border = "1px solid red";
                target.parentNode.children[1].style.backgroundColor = "skyblue";
            }
        })
        oUl.onmouseout = function(){
            var e = e || event;
            var target = e.target || e.srcElement;
            if( target.tagName.toLowerCase() == "img" ){
                target.style.border = "0";
                target.parentNode.children[1].style.backgroundColor = "";
            }
        }
    </script>
  • 相关阅读:
    (译)构建Async同步基元,Part 3 AsyncCountdownEvent
    (译)构建Async同步基元,Part 5 AsyncSemaphore
    SICP学习笔记(P3P17)
    关于汇编语言寄存器和指令操作的整理
    VS2010和IE8是怎样让"Ctrl+鼠标滚轮的上下操作"实现改变字体或页面大小的
    "六度空间"的应用——找出两个陌生人之间的关系(二)
    关于QQ一些功能的实现(二)
    用Socket做一个局域网聊天工具
    SICP学习笔记(P27P28)
    算法练习 (二)
  • 原文地址:https://www.cnblogs.com/tis100204/p/10319278.html
Copyright © 2011-2022 走看看