不知道什么原因,在IE上运行出错,在firefox运行正确,代码如下
<!---###html###->
<select id="select1" multiple="multiple" size=20>
<option>可以选择的水果</option>
<option>--------------</option>
<option value="大香蕉">香蕉</option>
<option value="大苹果">苹果</option>
<option value="大橘子">橘子</option>
<option value="大火龙果">火龙果</option>
</select>
<input type="button" id="add" value=">>" onclick="javascript:addSelect()"/>
<input type="button" id="del" value="<<" onclick="javascript:delSelect()"/>
<select id="select2" multiple="multiple" size=20>
<option>已经选择的水果</option>
<option>--------------</option>
</select><!--###js###-->
function addSelect()
{
var mysel1=document.getElementById("select1");
var mysel2=document.getElementById("select2");
var index=mysel1.selectedIndex;
var len=mysel2.options.length;
if(index>1)
{
mysel2.options[len]=mysel1.options[index]; //出错,对象为空,或者不存在此对象
//mysel2.options[len].text=mysel1.options[index].value; //出错,没反应
}
};
<!---###html###->
<select id="select1" multiple="multiple" size=20>
<option>可以选择的水果</option>
<option>--------------</option>
<option value="大香蕉">香蕉</option>
<option value="大苹果">苹果</option>
<option value="大橘子">橘子</option>
<option value="大火龙果">火龙果</option>
</select>
<input type="button" id="add" value=">>" onclick="javascript:addSelect()"/>
<input type="button" id="del" value="<<" onclick="javascript:delSelect()"/>
<select id="select2" multiple="multiple" size=20>
<option>已经选择的水果</option>
<option>--------------</option>
</select><!--###js###-->
function addSelect()
{
var mysel1=document.getElementById("select1");
var mysel2=document.getElementById("select2");
var index=mysel1.selectedIndex;
var len=mysel2.options.length;
if(index>1)
{
mysel2.options[len]=mysel1.options[index]; //出错,对象为空,或者不存在此对象
//mysel2.options[len].text=mysel1.options[index].value; //出错,没反应
}
};
var option = new createElement('Option');
option.value = mysel1.options[index].value;
mysel2.appChild(option);
不知道对不对
var option = document.createElement('Option');
option.value = mysel1.options[index].value;
mysel2.appChild(option);
{
var mysel1=document.getElementById("select1");
var mysel2=document.getElementById("select2");
var index=mysel1.selectedIndex;
if(index>1)
{
mysel2.appendChild(mysel1.options[index]);
}
}
function addSelect(){
var mysel1=document.getElementById("select1");
var mysel2=document.getElementById("select2");
var index=mysel1.selectedIndex;
var len=mysel2.options.length;
//alert(len)
if(index>1){
var val=mysel1.options[index].value;
mysel2.options[len]=new Option(val,val);
}
};
不过我在IE上试了试,正常
在firefox上没反应,郁闷。。