• js实现元素添加样式


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head>
    <style>
    .red{color:red;}
    .blue{color:blue;}
    #w a{display:block;}
    .red img{display:block!important;}
    #w a img{display:none;}
    </style>
    <body>
    <div id="w">
        <a class="red" title="1">1<img src="" width="100" height="50" alt="1"></a>
        <a title="2">2<img src="" width="100" height="50" alt="2"></a>
        <a title="3">3<img src="" width="100" height="50" alt="3"></a>
        <a title="4">4<img src="" width="100" height="50" alt="4"></a>
    </div>
    <script>
    window.onload=function(){
    var oD=document.getElementById("w");
    var oA=oD.getElementsByTagName("a");
    var oImg=oD.getElementsByTagName("img");
    for(var i=0;i<oA.length;i++){
    oA[i].onclick=function(){
    //onclick--onmouseover
    for(var i=0;i<oA.length;i++){ if(this.title==oA[i].title){
    //if(this==oA[i])
    //this(当前点击)
    //oA[i]循环中被选择
    this.className="red"; oImg[i].style.display="block"; } else{ oA[i].className="blue"; oImg[i].style.display="none"; } } }; } }; </script> </body> </html>

    类似:http://blog.163.com/fan_yishan/blog/static/4769221320141241517368/

    思路有些乱,望指教!

  • 相关阅读:
    检测单链表是否含有环
    巧用正则和document.location.search获取URL参数的值
    网站前端性能优化
    Ubuntu 10.10 wubi安装错误处理
    SQL中随机数函数rand()简介
    C#实现智能提示(提示补全)功能
    重装系统使之svn再次复活
    MongoDB安装
    mongodb查询
    解决iframe中跨域session丢失的问题
  • 原文地址:https://www.cnblogs.com/dream-w/p/4806790.html
Copyright © 2020-2023  润新知