有个js问题

顾君彦 北京紫博蓝网络发展有限公司 技术总监  2009-02-01 04:46:45
根据网上的代码,无法创建出select
代码如下:

JScript code
<script language="javascript">
function createSelect()
{
var mySelect = document.createElement("select");
mySelect.id = "mySelect";
document.body.appendChild(mySelect);
addOption();
}

function addOption()
{
var obj=document.getElementById('mySelect');
obj.option = new Option("123","123");
}
creatSelect();
</script>






请教一下,哪里有问题
...全文
45 点赞 收藏 4
写回复
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
lianhui1122 2009-02-01
<body>
<script language="javascript">
createSelect();
</script>
</body>
回复
lianhui1122 2009-02-01
补充下createSelect(); 要放在<body></body>之间
回复
独行创业路 2009-02-01
JScript code
<html>
<head>
</head>
<body>

<script type="text/javascript">
function createSelect()
{
var select1 = document.createElement("select");
var ooption = new Array();
ooption[0] = "one";
ooption[1] = "two";
ooption[2] = "three";
ooption[3] = "four";
ooption[4] = "five";
ooption[5] = "six";
ooption[6] = "seven";
ooption[7] = "eight";
ooption[8] = "nine";
ooption[9] = "ten";
for(var i=0;i<10;i++)
{
select1.options[i] = new Option(ooption[i], ooption[i]);
}
document.body.appendChild(select1);
}
createSelect();
</script>

</body>
</html>




回复
lianhui1122 2009-02-01
JScript code
<script language="javascript">
function createSelect()
{
var mySelect = document.createElement("select");
mySelect.id = "mySelect";
document.body.appendChild(mySelect);
addOption();
}

function addOption()
{
var obj=document.getElementById('mySelect');
obj.option[index] = new Option("123","123");
}
creatSelect();
</script>
回复
发动态
发帖子
Ajax
创建于2007-09-28

5.2w+

社区成员

Web 开发 Ajax
申请成为版主
社区公告
暂无公告