JavaScript新手对有些语法有些疑惑,请高手解惑:
描述:
新建asp.net页面
服务器控件ListBox两个
Html控件 button两个
见代码
<body style=" text-align:center;">
<form id="form1" runat="server">
<div>
<asp:ListBox ID="listLeft" runat="server" Height="199px" Width="160px" >
</asp:ListBox>
<input id="turnRight" type="button" onclick ='getLeftListSelected()' value=">>" style=" top:100px; position: absolute;"/>
<input id="turnLeft" type="button" onclick ='getRightListSelected()' value="<<" style=" top:140px; " />
<asp:ListBox ID="listRight" runat="server" Height="199px" Width="160px">
<asp:ListItem>试验1</asp:ListItem>
<asp:ListItem>试验2</asp:ListItem>
<asp:ListItem>试验3</asp:ListItem>
<asp:ListItem>试验4</asp:ListItem>
<asp:ListItem>试验5</asp:ListItem>
<asp:ListItem>试验6</asp:ListItem>
</asp:ListBox>
</div>
</form>
</body>
<form id="form1" runat="server">
<div>
<asp:ListBox ID="listLeft" runat="server" Height="199px" Width="160px" >
</asp:ListBox>
<input id="turnRight" type="button" onclick ='getLeftListSelected()' value=">>" style=" top:100px; position: absolute;"/>
<input id="turnLeft" type="button" onclick ='getRightListSelected()' value="<<" style=" top:140px; " />
<asp:ListBox ID="listRight" runat="server" Height="199px" Width="160px">
<asp:ListItem>试验1</asp:ListItem>
<asp:ListItem>试验2</asp:ListItem>
<asp:ListItem>试验3</asp:ListItem>
<asp:ListItem>试验4</asp:ListItem>
<asp:ListItem>试验5</asp:ListItem>
<asp:ListItem>试验6</asp:ListItem>
</asp:ListBox>
</div>
</form>
</body>
我的javaScript实现 代码
代码
<script type="text/javascript" >
// 从右边列表往左移
function getRightListSelected()
{
var lbRight = document.getElementById("listRight");
var lbLeft = document.getElementById("listLeft");
for( var i = 0;i< lbRight.options.length;++i )
{
if( lbRight.options[i].selected ){
lbLeft.appendChild( lbRight[i] );
}
}
}
// 从左列表往右移
function getLeftListSelected()
{
var lbRight = document.getElementById("listRight");
var lbLeft = document.getElementById("listLeft");
for( var i = 0;i< lbLeft.options.length;++i )
{
if( lbLeft.options[i].selected ){
lbRight.appendChild( lbLeft[i] );
}
}
}
</script>
// 从右边列表往左移
function getRightListSelected()
{
var lbRight = document.getElementById("listRight");
var lbLeft = document.getElementById("listLeft");
for( var i = 0;i< lbRight.options.length;++i )
{
if( lbRight.options[i].selected ){
lbLeft.appendChild( lbRight[i] );
}
}
}
// 从左列表往右移
function getLeftListSelected()
{
var lbRight = document.getElementById("listRight");
var lbLeft = document.getElementById("listLeft");
for( var i = 0;i< lbLeft.options.length;++i )
{
if( lbLeft.options[i].selected ){
lbRight.appendChild( lbLeft[i] );
}
}
}
</script>
我想合并后的js代码:
代码
<script type="text/javascript" >
// 从一个表移到另外一个表 Bug无法识别objfrom
function Move( objfrom,objto )
{
var lbRight = document.getElementById( objfrom );
var lbLeft = document.getElementById( objto );
for( var i = 0;i< lbRight.options.length;++i )
{
if( lbRight.options[i].selected ){
lbLeft.appendChild( lbRight[i] );
}
}
}
</script>
// 从一个表移到另外一个表 Bug无法识别objfrom
function Move( objfrom,objto )
{
var lbRight = document.getElementById( objfrom );
var lbLeft = document.getElementById( objto );
for( var i = 0;i< lbRight.options.length;++i )
{
if( lbRight.options[i].selected ){
lbLeft.appendChild( lbRight[i] );
}
}
}
</script>
提示错误:
lbRight.options对象无法识别
望高手解惑。。。谢谢!!