当前位置:编程学习 > JS >>

js 用一个提交按钮保存滑块的当前位置

答案:不知道你想保存在哪,下面的代码是获取id=“box”的div元素当前位置后,将其设置成div元素的name属性。通过alert(GETatrr)值可以看出name属性已经设置成功。 ============================================= function save_site(){ var box_left = document.getElementById("box").offsetLeft; var box_top = document.getElementById("box").offsetTop; box.setAttribute("name",box_left+","+box_top); var GETatrr =box.attributes['name'].nodeValue; alert(GETatrr); }
其他:<HTML>
 <HEAD>
  <TITLE> New Document </TITLE>
  <META NAME="Generator" CONTENT="EditPlus">
  <META NAME="Author" CONTENT="">
  <META NAME="Keywords" CONTENT="">
  <META NAME="Description" CONTENT="">
 </HEAD>
    <script language="javascript">
        function checkSel() {
   //获取select对象
            var selectNode1 = document.getElementById("selectNode1");
   var selectNode2 = document.getElementById("selectNode2");
   var selectNode3 = document.getElementById("selectNode3");
   //获取labl对象
            var lb = document.getElementById("lb1");
   //动态创建表格,也可以不动态创建,可再body中把表格写好,再这给它们设值。
   var table = document.createElement("table");
   table.border = "1"; //设置边框
   //创建一行
   var tr = table.insertRow();
   //创建三列,并将三个select的值设置到这三列中。
   var td0 = tr.insertCell();
   td0.innerText = selectNode1.options[selectNode1.selectedIndex].value;
   var td1 = tr.insertCell();
   td1.innerText = selectNode2.options[selectNode2.selectedIndex].value;
   var td2 = tr.insertCell();
   td2.innerText = selectNode3.options[selectNode3.selectedIndex].value;
   
   //将创建的table添加到labl中去。
   lb.appendChild(table);
        }
    </script>
 <BODY>
     <div>
    <select id="selectNode1">
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
    </select>
 <select id="selectNode2">
        <option value="a">a</option>
        <option value="b">b</option>
        <option value="c">c</option>
    </select>
 <select id="selectNode3">
        <option value="A">A</option>
        <option value="B">B</option>
        <option value="C">C</option>
    </select>
    <br />
    <label id="lb1"></label>
    <br />
    <input id="btn1" type="button" value="button" onclick="checkSel()" />
    </div> 
 </BODY>
</HTML>
 

上一个:搜狗浏览器能否debug js脚本?
下一个:JS获取来路的问题

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,