• Window.document对象 轮播练习


    Window.document对象

    一、找到元素:

        docunment.getElementById("id");根据id找,最多找一个;
        var a =docunment.getElementById("id");将找到的元素放在变量中;
        docunment.getElementsByName("name");根据name找,找出来的是数组;
        docunment.getElementsByTagName("name");根据标签名找,找出来的是数组;
        docunment.getElementsByClassName("name") 根据classname找,找出来的是数组;

    二、操作内容:

     1. 非表单元素:

    1)获取内容:

    alert(a.innerHTML);标签里的html代码和文字都获取了,标签里面的所有内容。

    如:body中有这么一个div:

    <div id="me"><b>试试吧</b></div>

    在script中用innerHTML获取div中的内容:

        var a= document.getElementById("me");
        alert(a.innerHTML);

    结果如下图:

    alert(a.innerText);只取里面的文字
        alert(a.outerHTML);包括标签本身的内容(简单了解)

    2)设置内容:

    a.innerHTML = "<font color=red >hello world </font>";

    如果用设置内容代码结果如下,div中的内容被替换了:

     

    a.innerText会将赋的东西原样呈现

    清空内容:赋值个空字符串

    2. 表单元素:

    1)获取内容,有两种获取方式:

    var t = document.f1.t1; form表单ID为f1里面的ID为t1的input;
        var t = document.getElementById("id"); 直接用ID获取。

    alert(t.value); 获取input中的value值;
        alert(t.innerHTML); 获取<textarea> 这里的值 </textarea>;

    2)设置内容: t.value="内容改变";

    3. 一个小知识点:

    <a href="http://www.baidu.com" onclick ="return false">转向百度</a> ;加了return flase则不会跳转,默认是return true会跳转。

    按钮也一样,如果按钮中设置return flase 则不会进行提交,利用这个可以对提交跳转进行控制。

    三、操作属性

    首先利用元素的ID找到该元素,存于一个变量中:

    var a = document.getElementById("id");

    然后可以对该元素的属性进行操作:

    a.setAttribute("属性名","属性值"); 设置一个属性,添加或更改都可以;

    a.getAttribute("属性名");获取属性的值;

    a.removeAttribute("属性名");移除一个属性。

    例子1:做一个问题,如果输入的答案正确则弹出正确,错误弹出错误;

    这里在text里面写了一个daan属性,里面存了答案的值,点击检查答案的时候cheak输入的内容和答案是否一样:

    Body中代码:

    <form>中华民国成立于哪一年?<input type="text" daan="1912年" value="" id="t1" name="t1" />
    <input type="button" onclick="check()" id="t2" name="t2" value="检查答案" /></form>

    JS中的代码:

    function check()
    {
        var a=document.getElementById("t1");
        var a1=a.value;
        var a2=a.getAttribute("daan");
        if(a1==a2)
        {
            alert("恭喜你答对了!");
        }
        else
        {
            alert("笨蛋!");
        }
    }
     

    回答正确时的结果

    例子2: 同意按钮,倒计时10秒,同意按钮变为可提交的,这里用了操作属性:disable,来改变按钮的状态,当disabled=”disabled”时按钮不可用。

    body中的代码:

    <form><input type="submit" id="b1" name="b1" value="同意(10)" disabled="disabled" /></form>

    JS中的代码:

    var n=10;
    var a= document.getElementById("b1");
    function bian()
    {
        n--;
        if(n==0)
        {
            a.removeAttribute("disabled");
            a.value="同意";
            return;
        }
        else
        {
            a.value= "同意("+n+")";
            window.setTimeout("bian()",1000);
        }
    }
    window.setTimeout("bian()",1000);

    运行的结果:

    四、操作样式

    首先利用元素的ID找到该元素,存于一个变量中:

    var a = document.getElementById("id");

    然后可以对该元素的属性进行操作:

    a.style="" ; 操作此ID样式的属性。

    样式为CSS中的样式,所有的样式都可以用代码进行操作。

    document.body.style.backgroundColor="颜色"; 整个窗口的背景色。

    操作样式的class:a.className="样式表中的classname" 操作一批样式

    例子1:展示图片的自动和手动切换;

    Body中的代码,做一个有背景图片的div和两侧的控制对象:

     </div>
                <div id="tuijian" style=" background-image:url(imges/tj1.jpg);">
                <div class="pages" id="p1" onclick="dodo(-1)"></div>
                <div class="pages" id="p2" onclick="dodo(1)"></div>
            </div>

    样式表中的代码:

    <style type="text/css">
    *{
        margin:0px auto;
        padding:0px;
        font-family:"微软雅黑";
    }
    #tuijian{
        760px;
        height:350px;
        background-repeat:no-repeat;
    }
    .pages{
        top:200px;
        background-color:#000;
        background-position:center;
        background-repeat:no-repeat;
        opacity: 0.4;
         30px;
        height:60px;
        
    }
    #p1{
        background-image:url(imges/prev.png);
        float:left;
        margin:150px 0px 0px 10px;
        
    }
    #p2{
        background-image:url(imges/next.png);
        float:right;
        margin:150px 10px 0px 0px;
    }
    </style>

    JS中的代码,这里主要是每隔3秒中调用一下huan()函数,来将背景图片的样式修改,在点击左右切换的时候变为手动切换,自动切换停止:

    <script language="javascript">var jpg =new Array();
    jpg[0]="url(imges/tj1.jpg)";
    jpg[1]="url(imges/tj2.jpg)";
    jpg[2]="url(imges/tj3.jpg)";
    var tjimg = document.getElementById("tuijian");
    var xb=0;
    var n=0;
    function huan()
    {
        xb++;
        if(xb == jpg.length)
        {
            xb=0;
        }
        
        tjimg.style.backgroundImage=jpg[xb];
        if(n==0)
        {
        var id = window.setTimeout("huan()",3000);
        }
        
        
    }
    function dodo(m)
    {   
        n=1;
        xb = xb+m;
        if(xb < 0)
        {
            xb = jpg.length-1;
        }
        else if(xb >= jpg.length)
        {
            xb = 0;
        }
        tjimg.style.backgroundImage=jpg[xb];
    }
    window.setTimeout("huan()",3000);</script>

    效果如下图:

     

    五、相关元素操作:

    var a = document.getElementById("id");找到a;

    var b = a.nextSibling,找a的下一个同辈元素,注意包含空格;

    var b = a.previousSibling,找a的上一个同辈元素,注意包含空格;

    var b = a.parentNode,找a的上一级父级元素;

    var b = a.childNodes,找出来的是数组,找a的下一级子元素;

    var b = a.firstChild,第一个子元素,lastChild最后一个,childNodes[n]找第几个;

    alert(nodes[i] instanceof Text); 判断是不是文本,是返回true,不是返回flase,用if判断它的值是不是false,可以去除空格。

    六、元素的创建、添加、删除:

    var a = document.getElementById("id");找到a;

    var obj = document.createElement("标签名");创建一个元素

    obj.innerHTML = "hello world";添加的时候首先需要创建出一个元素。

    a.appendChild(obj);向a中添加一个子元素。

    a.removeChild(obj);删除一个子元素。

    列表中a.selectedIndex:选中的是第几个;

    //a.options[a.selectIndex]按下标取出第几个option对象

    七、字符串的操作:

    var s = new String(); 或var s ="aaaa";

    var s = "hello world";

    alert(s.toLowerCase());转小写 toUpperCase() 转大写

    alert(s.substring(3,8));从第三个位置截取到第八个位置

    alert(s.substr(3,8));从第三个位置开始截取,截取八个字符长度,不写后面的数字是截到最后.

    s.split('');将字符换按照指定的字符拆开,放入数组,自动排序

    s.length是属性

    s.indexOf("world");world在字符串中第一次出现的位置,没有返回-1

    s.lastIndexOf("o");o在字符串中最后一次出现的位置

    八、日期时间的操作

    var d = new Date();当前时间

    d.setFullYear(2015,11,6);/*在想要设置的月份上减1设置*/

    d.getFullYear:取年份;

     d.getMonth():取月份,取出来的少1;

    d.getDate():取天;

    d.getDay():取星期几

    d.getHours():取小时;

    d.getMinutes():取分钟;d.getSeconds():取秒

    d.setFullYear():设置年份,设置月份的时候注意-1。

    九、数学函数的操作

    Math.ceil();大于当前小数的最小整数

    Math.floor();小鱼当前小数的最大整数

    Math.sqrt();开平方

    Math.round();四舍五入

    Math.random();随机数,0-1之间

    十、小知识点

    外面双引号,里面的双引号改为单引号;

    在div里面行高设置时,无论设置多么高,所占用的行默认在中间位置(div上下区域内中间——【默认】垂直居中)。

    文本框取出来的值是字符串,需要用parseint()转化为数字

    s.match(reg); s代表一个字符串,reg代表一个字符串,两者进行匹配,如果两个字符串不匹配,返回一个null。

    三、document:
    1.找
    var d = document.getElementById("元素的ID");
    var d = document.getElementsByName("元素名称")
    var d = document.getElementsByTagName("标签名")

    2.操作元素内容:
    (1)表单元素:文本(input:type=text,input:type=password;textarea;input:type=hidden)按钮(submit,reset,button image)选择(radio,checkbox,select,file)
    d.value=xxxx;
    var s = d.value;

    (2)非表单元素:h1...h6,p,div,ul,ol,li
    d.innerHTML = xxxx;
    var s = d.innerHTML;

    3.操作元素属性:
    d.setAttribute(名,值)
    var s = d.getAttribute(名)
    d.removeAttribute(名);

    4.操作元素样式:
    (1)内联样式:
    d.style.backgroundColor = "#FFFF00";
    var s = d.style.backgroundColor;
    (2)class属性:
    d.className=""
    5.操作相关元素:
    父,子,兄,弟

    练习 :

    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <style type="text/css">
    *{ margin:0px; padding:0px;}
    #tu{ 1280px; height:480px; position:relative; overflow:hidden; margin:30px auto;}
    #ta{ 3840px; height:480px; margin-left:0px; transition:0.7s;}
    .lie{1263px; height:480px; background-size:contain; overflow:hidden;}
    .left{30px; height:70px; position:relative; float:left; color:#FFF; background-color:#000; font-weight:bold; font-size:30px;
    opacity:0.4; cursor:pointer; line-height:70px;top:-180px;text-align:center;left:0px; z-index:99; overflow:hidden} .right{30px;height:70px;position:relative; float:right; color:#FFF; background-color:#000; font-weight:bold;
    font-size:30px;opacity:0.4; cursor:pointer; line-height:70px;top:-180px; text-align:center;right:0px; z-index:99; overflow:hidden} .left:hover{ overflow:visible; opacity:0.7} .right:hover{ overflow:visible;opacity:0.7} #zuo{ 150px;height:70px; position:relative; float:left;top:-70px; left:30px;background-color:#000;} #zuo1{130px;height:50px; background-size:contain; margin:10px 10px;} #you{ 150px;height:70px; position:relative; float:right;top:-70px;right:30px;background-color:#000;} #you1{130px;height:50px; background-size:contain; margin:10px 10px;} #xdian1{ 20px; height:20px;color:white; line-height:20px; position:relative; float:right; right:30px; bottom:30px; cursor:pointer;} #xdian2{ 20px; height:20px; color:white; line-height:20px; position:relative; float:right; right:30px; bottom:30px; cursor:pointer;} #xdian3{ 20px; height:20px; color:yellow; line-height:20px; position:relative; float:right; right:30px; bottom:30px; cursor:pointer;} </style> </head> <body> <div id="tu" onmouseover="pause()" onmouseout="contin()"> <table id="ta" cellpadding="0" cellspacing="0"> <tr height="480px"> <td class="lie" style="background-image:url(../%E8%AE%BE%E8%AE%A1/%E4%B8%BB%E9%A1%B5/2016102513556ix3te.jpg)"></td> <td class="lie" style="background-image:url(../%E8%AE%BE%E8%AE%A1/%E4%B8%BB%E9%A1%B5/201611011322xmobzr.jpg)"></td> <td class="lie" style="background-image:url(../%E8%AE%BE%E8%AE%A1/%E4%B8%BB%E9%A1%B5/2016100510182xjx6n.jpg)"></td> </tr> </table> <div class="left" onclick="dian(-1)">< <div id="zuo"> <div id="zuo1" style="background-image:url(../%E8%AE%BE%E8%AE%A1/%E4%B8%BB%E9%A1%B5/2016100510182xjx6n.jpg)" > </div> </div> </div> <div class="right" onclick="dian(1)">> <div id="you"> <div id="you1" style="background-image:url(../%E8%AE%BE%E8%AE%A1/%E4%B8%BB%E9%A1%B5/201611011322xmobzr.jpg)" > </div> </div> </div> <div id="xdian1" onclick="dianji(1)">●</div> <div id="xdian2" onclick="dianji(2)">●</div> <div id="xdian3" onclick="dianji(3)">●</div> </div> </body> </html> <script language="javascript"> document.getElementById("ta").style.marginLeft="0px"; var xiaodian1=document.getElementById("xdian1"); var xiaodian2=document.getElementById("xdian2"); var xiaodian3=document.getElementById("xdian3"); function huan() { var tp=document.getElementById("ta"); var a=parseInt(tp.style.marginLeft); var tpy=document.getElementById("you1"); var tpz=document.getElementById("zuo1"); if(a<=-2560) { tp.style.marginLeft="0px"; tpz.style.backgroundImage="url(../%E8%AE%BE%E8%AE%A1/%E4%B8%BB%E9%A1%B5/2016100510182xjx6n.jpg)"; tpy.style.backgroundImage="url(../%E8%AE%BE%E8%AE%A1/%E4%B8%BB%E9%A1%B5/201611011322xmobzr.jpg)"; tpz.style.transition="0.7s"; tpy.style.transition="0.7s"; xiaodian3.style.color="yellow"; xiaodian2.style.color="white"; xiaodian1.style.color="white"; } else if(a==-1280) { tp.style.marginLeft=-2560+"px"; tpz.style.backgroundImage="url(../%E8%AE%BE%E8%AE%A1/%E4%B8%BB%E9%A1%B5/201611011322xmobzr.jpg)"; tpy.style.backgroundImage="url(../%E8%AE%BE%E8%AE%A1/%E4%B8%BB%E9%A1%B5/2016102513556ix3te.jpg)"; tpz.style.transition="0.7s"; tpy.style.transition="0.7s"; xiaodian1.style.color="yellow"; xiaodian2.style.color="white"; xiaodian3.style.color="white"; } else if(a==0) { tp.style.marginLeft=-1280+"px"; tpy.style.backgroundImage="url(../%E8%AE%BE%E8%AE%A1/%E4%B8%BB%E9%A1%B5/2016100510182xjx6n.jpg)"; tpz.style.backgroundImage="url(../%E8%AE%BE%E8%AE%A1/%E4%B8%BB%E9%A1%B5/2016102513556ix3te.jpg)"; tpz.style.transition="0.7s"; tpy.style.transition="0.7s"; xiaodian2.style.color="yellow"; xiaodian1.style.color="white"; xiaodian3.style.color="white"; } id=window.setTimeout("huan()",3000); } var id=window.setTimeout("huan()",3000); function pause() { window.clearTimeout(id); } function contin() { id = window.setTimeout("huan()",3000); } function dian(m) { var tp=document.getElementById("ta"); var a=parseInt(tp.style.marginLeft); var tpy=document.getElementById("you1"); var tpz=document.getElementById("zuo1"); if(m==-1) { if(a==0) { tp.style.marginLeft=-2560+"px"; tpz.style.backgroundImage="url(../%E8%AE%BE%E8%AE%A1/%E4%B8%BB%E9%A1%B5/201611011322xmobzr.jpg)"; tpy.style.backgroundImage="url(../%E8%AE%BE%E8%AE%A1/%E4%B8%BB%E9%A1%B5/2016102513556ix3te.jpg)"; tpz.style.transition="0.7s"; tpy.style.transition="0.7s"; xiaodian1.style.color="yellow"; xiaodian2.style.color="white"; xiaodian3.style.color="white"; } else if(a==-1280) { tp.style.marginLeft="0px"; tpz.style.backgroundImage="url(../%E8%AE%BE%E8%AE%A1/%E4%B8%BB%E9%A1%B5/2016100510182xjx6n.jpg)"; tpy.style.backgroundImage="url(../%E8%AE%BE%E8%AE%A1/%E4%B8%BB%E9%A1%B5/201611011322xmobzr.jpg)"; tpz.style.transition="0.7s"; tpy.style.transition="0.7s"; xiaodian3.style.color="yellow"; xiaodian2.style.color="white"; xiaodian1.style.color="white"; } else if(a==-2560) { tp.style.marginLeft=-1280+"px"; tpy.style.backgroundImage="url(../%E8%AE%BE%E8%AE%A1/%E4%B8%BB%E9%A1%B5/2016100510182xjx6n.jpg)"; tpz.style.backgroundImage="url(../%E8%AE%BE%E8%AE%A1/%E4%B8%BB%E9%A1%B5/2016102513556ix3te.jpg)"; tpz.style.transition="0.7s"; tpy.style.transition="0.7s"; xiaodian2.style.color="yellow"; xiaodian1.style.color="white"; xiaodian3.style.color="white"; } } else if(m==1) { if(a==-2560) { tp.style.marginLeft="0px"; tpz.style.backgroundImage="url(../%E8%AE%BE%E8%AE%A1/%E4%B8%BB%E9%A1%B5/2016100510182xjx6n.jpg)"; tpy.style.backgroundImage="url(../%E8%AE%BE%E8%AE%A1/%E4%B8%BB%E9%A1%B5/201611011322xmobzr.jpg)"; tpz.style.transition="0.7s"; tpy.style.transition="0.7s"; xiaodian3.style.color="yellow"; xiaodian2.style.color="white"; xiaodian1.style.color="white"; } else if(a==-1280) { tp.style.marginLeft=-2560+"px"; tpz.style.backgroundImage="url(../%E8%AE%BE%E8%AE%A1/%E4%B8%BB%E9%A1%B5/201611011322xmobzr.jpg)"; tpy.style.backgroundImage="url(../%E8%AE%BE%E8%AE%A1/%E4%B8%BB%E9%A1%B5/2016102513556ix3te.jpg)"; tpz.style.transition="0.7s"; tpy.style.transition="0.7s"; xiaodian1.style.color="yellow"; xiaodian2.style.color="white"; xiaodian3.style.color="white"; } else if(a==0) { tp.style.marginLeft=-1280+"px"; tpy.style.backgroundImage="url(../%E8%AE%BE%E8%AE%A1/%E4%B8%BB%E9%A1%B5/2016100510182xjx6n.jpg)"; tpz.style.backgroundImage="url(../%E8%AE%BE%E8%AE%A1/%E4%B8%BB%E9%A1%B5/2016102513556ix3te.jpg)"; tpz.style.transition="0.7s"; tpy.style.transition="0.7s"; xiaodian2.style.color="yellow"; xiaodian1.style.color="white"; xiaodian3.style.color="white"; } } } function dianji(i) { var tp=document.getElementById("ta"); var tpy=document.getElementById("you1"); var tpz=document.getElementById("zuo1"); if(i==3) { tp.style.marginLeft="0px"; tpz.style.backgroundImage="url(../%E8%AE%BE%E8%AE%A1/%E4%B8%BB%E9%A1%B5/2016100510182xjx6n.jpg)"; tpy.style.backgroundImage="url(../%E8%AE%BE%E8%AE%A1/%E4%B8%BB%E9%A1%B5/201611011322xmobzr.jpg)"; tpz.style.transition="0.7s"; tpy.style.transition="0.7s"; xiaodian3.style.color="yellow"; xiaodian2.style.color="white"; xiaodian1.style.color="white"; } else if(i==2) { tp.style.marginLeft=-1280+"px"; tpy.style.backgroundImage="url(../%E8%AE%BE%E8%AE%A1/%E4%B8%BB%E9%A1%B5/2016100510182xjx6n.jpg)"; tpz.style.backgroundImage="url(../%E8%AE%BE%E8%AE%A1/%E4%B8%BB%E9%A1%B5/2016102513556ix3te.jpg)"; tpz.style.transition="0.7s"; tpy.style.transition="0.7s"; xiaodian2.style.color="yellow"; xiaodian1.style.color="white"; xiaodian3.style.color="white"; } else if(i==1) { tp.style.marginLeft=-2560+"px"; tpz.style.backgroundImage="url(../%E8%AE%BE%E8%AE%A1/%E4%B8%BB%E9%A1%B5/201611011322xmobzr.jpg)"; tpy.style.backgroundImage="url(../%E8%AE%BE%E8%AE%A1/%E4%B8%BB%E9%A1%B5/2016102513556ix3te.jpg)"; tpz.style.transition="0.7s"; tpy.style.transition="0.7s"; xiaodian1.style.color="yellow"; xiaodian2.style.color="white"; xiaodian3.style.color="white" } } </script>


    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <style type="text/css">
    *{ margin:0px; padding:0px;}
    #tu{ 800px; height:500px; position:relative; overflow:hidden; margin:30px auto;}
    #ta{ 4000px; height:500px; margin-left:0px; transition:0.7s;}
    .lie{800px; height:500px; background-size:contain}
    .left{40px; height:100px; position:relative; float:left; color:#FFF; background-color:#000; font-weight:bold; font-size:36px;
    opacity:0.4; cursor:pointer; line-height:100px;top:-280px;text-align:center;left:0px; z-index:99} .right{40px;height:100px;position:relative; float:right; color:#FFF; background-color:#000; font-weight:bold; font-size:36px;opacity:0.4;
    cursor:pointer; line-height:100px;top:-280px; text-align:center;right:0px; z-index:99} #tu2{ 612px; height:79px; position:relative; margin:20px auto;} #lie1{120px; height:75px; position:relative; float:left; border:1px solid #999; cursor:pointer;} #lie2{120px; height:75px; position:relative; float:left; border:1px solid #999; cursor:pointer;} #lie3{120px; height:75px; position:relative; float:left; border:1px solid #999; cursor:pointer;} #lie4{120px; height:75px; position:relative; float:left; border:1px solid #999; cursor:pointer;} #lie5{120px; height:75px; position:relative; float:left; border:1px solid #999; cursor:pointer;} img{120px; height:75px;} </style> </head> <body> <div id="tu" onmouseover="pause()" onmouseout="contin()"> <table id="ta" cellpadding="0" cellspacing="0"> <tr height="500px"> <td class="lie" style="background-image:url(%E6%96%B0%E5%BB%BA%E6%96%87%E4%BB%B6%E5%A4%B9/Images/1.jpg)"></td> <td class="lie" style="background-image:url(%E6%96%B0%E5%BB%BA%E6%96%87%E4%BB%B6%E5%A4%B9/Images/2.jpg)"></td> <td class="lie" style="background-image:url(%E6%96%B0%E5%BB%BA%E6%96%87%E4%BB%B6%E5%A4%B9/Images/3.jpg)"></td> <td class="lie" style="background-image:url(%E6%96%B0%E5%BB%BA%E6%96%87%E4%BB%B6%E5%A4%B9/Images/4.jpg)"></td> <td class="lie" style="background-image:url(%E6%96%B0%E5%BB%BA%E6%96%87%E4%BB%B6%E5%A4%B9/Images/5.jpg)"></td> </tr> </table> <div class="left" onclick="dian(-1)"><</div> <div class="right" onclick="dian(1)">></div> </div> <div id="tu2"> <div id="lie1" onclick="dianji(1)"><img src="新建文件夹/Images/1.jpg" /></div> <div id="lie2" onclick="dianji(2)"><img src="新建文件夹/Images/2.jpg" /></div> <div id="lie3" onclick="dianji(3)"><img src="新建文件夹/Images/3.jpg" /></div> <div id="lie4" onclick="dianji(4)"><img src="新建文件夹/Images/4.jpg" /></div> <div id="lie5" onclick="dianji(5)"><img src="新建文件夹/Images/5.jpg" /></div> </div> </body> </html> <script language="javascript"> document.getElementById("ta").style.marginLeft="0px"; function huan() { var tp=document.getElementById("ta"); var a=parseInt(tp.style.marginLeft); if(a<=-3200) { tp.style.marginLeft="0px"; dj[0].style.borderColor="red"; dj[2].style.borderColor="#999"; dj[3].style.borderColor="#999"; dj[4].style.borderColor="#999"; dj[1].style.borderColor="#999"; } else { tp.style.marginLeft=(a-800)+"px"; dj[0].style.borderColor="#999"; dj[2].style.borderColor="#999"; dj[3].style.borderColor="#999"; dj[4].style.borderColor="#999"; dj[1].style.borderColor="#999"; dj[(800-a)/800].style.borderColor="red"; } id=window.setTimeout("huan()",3000); } var id=window.setTimeout("huan()",3000); function pause() { window.clearTimeout(id); } function contin() { id = window.setTimeout("huan()",3000); } function dian(m) { var tp=document.getElementById("ta"); var a=parseInt(tp.style.marginLeft); if(m==-1) { if(a==0) { tp.style.marginLeft=(a-3200)+"px"; dj[0].style.borderColor="#999"; dj[2].style.borderColor="#999"; dj[3].style.borderColor="#999"; dj[4].style.borderColor="#999"; dj[1].style.borderColor="#999"; dj[(3200-a)/800].style.borderColor="red"; } else { tp.style.marginLeft=(a+800)+"px"; dj[0].style.borderColor="#999"; dj[2].style.borderColor="#999"; dj[3].style.borderColor="#999"; dj[4].style.borderColor="#999"; dj[1].style.borderColor="#999"; dj[(-800-a)/800].style.borderColor="red"; } } else if(m==1) { if(a==-3200) { tp.style.marginLeft="0px"; dj[0].style.borderColor="red"; dj[2].style.borderColor="#999"; dj[3].style.borderColor="#999"; dj[4].style.borderColor="#999"; dj[1].style.borderColor="#999"; } else { tp.style.marginLeft=(a-800)+"px"; dj[0].style.borderColor="#999"; dj[2].style.borderColor="#999"; dj[3].style.borderColor="#999"; dj[4].style.borderColor="#999"; dj[1].style.borderColor="#999"; dj[(800-a)/800].style.borderColor="red"; } } } var tp=document.getElementById("ta"); var dj=new Array; dj[0]=document.getElementById("lie1"); dj[1]=document.getElementById("lie2"); dj[2]=document.getElementById("lie3"); dj[3]=document.getElementById("lie4"); dj[4]=document.getElementById("lie5"); dj[0].style.borderColor="red"; function dianji(i) { if(i==1) { dj[0].style.borderColor="red"; dj[2].style.borderColor="#999"; dj[3].style.borderColor="#999"; dj[4].style.borderColor="#999"; dj[1].style.borderColor="#999"; tp.style.marginLeft="0px"; } else if(i==2) { dj[1].style.borderColor="red"; dj[2].style.borderColor="#999"; dj[3].style.borderColor="#999"; dj[4].style.borderColor="#999"; dj[0].style.borderColor="#999"; tp.style.marginLeft="-800px"; } else if(i==3) { dj[2].style.borderColor="red"; dj[1].style.borderColor="#999"; dj[3].style.borderColor="#999"; dj[4].style.borderColor="#999"; dj[0].style.borderColor="#999"; tp.style.marginLeft="-1600px"; } else if(i==4) { dj[3].style.borderColor="red"; dj[2].style.borderColor="#999"; dj[1].style.borderColor="#999"; dj[4].style.borderColor="#999"; dj[0].style.borderColor="#999"; tp.style.marginLeft="-2400px"; } else if(i==5) { dj[4].style.borderColor="red"; dj[2].style.borderColor="#999"; dj[3].style.borderColor="#999"; dj[1].style.borderColor="#999"; dj[0].style.borderColor="#999"; tp.style.marginLeft="-3200px"; } } </script>

      

      

  • 相关阅读:
    [bzoj3694]最短路
    [bzoj3172][Tjoi2013]单词
    [bzoj2243][SDOI2011]染色
    [bzoj1036][ZJOI2008]树的统计Count
    [学习笔记]树链剖分
    [bzoj4552][Tjoi2016][Heoi2016]排序
    [51nod1515]明辨是非
    [51nod1685]第k大区间
    [日常训练]training
    BZOJ3811: 玛里苟斯
  • 原文地址:https://www.cnblogs.com/maxin991025-/p/6029067.html
Copyright © 2020-2023  润新知