日期:2014-05-16  浏览次数:20375 次

动态数据存数据
<script>
 
function   creatSel(){
var   v1=document.getElementById( "sel ").value;

var   sel=document.createElement( "select ");  
var   item   =   new   Option( "+ "+v1, "+ "+v1);
var   item1   =   new   Option( "- "+v1, "- "+v1);
sel.options.add(item);
sel.options.add(item1);
//document.write
document.body.appendChild(sel);
}
</script>
</head>
<body>
<select   id= "sel "   onchange= "creatSel() "   name= "sel ">
<option   value= "1 "> v1 </option>
<option   value= "2 "> v2 </option>
<option   value= "3 "> v3 </option>
<option   value= "4 "> v4 </option>
</select>


    我想用动态数据保存每次   NEW出来的SEL里的值     可不知道怎么写,麻烦大家了  
  急   在线等!!

------解决方案--------------------
<html>
<head>
<title> new page </title>
<script>
var appendArray=new Array();
var num=0;
function creatSel(){
var v1=document.getElementById( "sel ").value;
var sel=document.createElement( "select ");
var item = new Option( "+ "+v1, "+ "+v1);
var item1 = new Option( "- "+v1, "- "+v1);
appendArray[num]= "+ "+v1;
sel.options.add(item);
sel.options.add(item1);
//document.write
var num1=num;
sel.onchange=changeValue(sel,num1);
document.body.appendChild(sel);
num++;
}
function changeValue(obj,num1){
return function(){appendArray[num1]=this.value;};
}
function show(){
var len=appendArray.length;
var append_arr=new Array();
var append_array=new Array();
for(var i=0;i <len;i++){
if(appendArray[i]> 0){
append_arr[append_arr.length]=appendArray[i];
}else{
append_array[append_array.length]=appendArray[i];
}
}
alert( "您添加了 "+append_arr.length+ "个 '+ '的select控件\n他们的值分别是: "+append_arr);
alert( "您添加了 "+append_array.length+ "个 '- '的select控件\n他们的值分别是: "+append_array);
alert( "您一共添加了 "+len+ "个select控件\n他们的值分别是: "+appendArray);
}
</script>
</head>
<body>
<select id= "sel " onchange= "creatSel() " name= "sel ">
<option value= "1 "> v1 </option>
<option value= "2 "> v2 </option>
<option value= "3 "> v3 </option>
<option value= "4 "> v4 </option>
</select>
<input type=button onclick= "show() " value= "测试结果 ">
</body>
</html>