求助,简单JS设置问题(好久没来,今天送分) RT,在JS中如何设置select name属性?我这么写的,是无效的: var sel=document.createElement("select"); sel.setAttribute("name","xxx"); //...求解啊!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 var sel=document.createElement("select");sel.options.name="xxx"//name属性?sel.options[i].text="xxx" //option 的名字 不是option的name和value是select的eg:<select name="xxx">....</select> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <META http-equiv="Content-Style-Type" content="text/css"> </head> <script language=javascript> window.onload=function(){ var sel= document.getElementById("sel"); sel.name="a"; alert(sel.name) } </script> <body> <div><select id=sel name="aaa"><div> </body></html> TO: BeenZ这样不行,我试过,在页面里也没有显示! 没显示alert语句还是?你的浏览器是什么啊?我在各个浏览器下面测试都通过了的啊发代码来看看 <body> <div><select id=sel name="aaa"><div> </body>你的代码有点小问题,你把select标签都写全了,再试试 你这样写:<script> function a(b){ alert(b.innerHTML); } </script> <body> <div onclick="a(this)" >test<select id=sel></select><div> </body>你看DIV里面的select是不是有name的 <script language=javascript> window.onload=function(){ var sel= document.createElement("<select name='aaa'>"); document.getElementById("pad").appendChild(sel); alert(document.getElementById("aaa").name) } </script> <body> <div id="pad"><div> </body> 楼上地高人,这样做是不行的啊;你可以试试,输出 div 中的内容,看看select 是不是有name 的 如果你用IE8的带开发个工具(F12),可以跟踪到动态的DOM的,select有name的 google map 中画圆. 哪位大侠愿意拔刀相助 关于Javascript的变量作用域的问题 诚寻Yahoo Widget 开发者,项目开发合作 js中如果复选框只有一个选项,怎么让其默认不被选择? 如何用javascript 实现按钮的隐藏和显示 關於字段值的計算 这一段起什么作用呢?? 如何操纵列表框? why?为何会这样? 城市下拉列表 打开关闭问题100分 document.getElementById的用法
var sel=document.createElement("select");
sel.options.name="xxx"//name属性?
sel.options[i].text="xxx" //option 的名字
是select的
eg:<select name="xxx">....</select>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<META http-equiv="Content-Style-Type" content="text/css"> </head>
<script language=javascript>
window.onload=function(){
var sel= document.getElementById("sel");
sel.name="a";
alert(sel.name)
} </script>
<body>
<div><select id=sel name="aaa"><div>
</body>
</html>
BeenZ这样不行,我试过,在页面里也没有显示!
发代码来看看
<div><select id=sel name="aaa"><div>
</body>
你的代码有点小问题,你把select标签都写全了,再试试
<script>
function a(b){
alert(b.innerHTML);
}
</script>
<body>
<div onclick="a(this)" >test<select id=sel></select><div>
</body>你看DIV里面的select是不是有name的
<script language=javascript>
window.onload=function(){
var sel= document.createElement("<select name='aaa'>");
document.getElementById("pad").appendChild(sel);
alert(document.getElementById("aaa").name)
}
</script>
<body>
<div id="pad"><div>
</body>
你可以试试,输出 div 中的内容,看看select 是不是有name 的