<form id= "Form1 " method= "post " runat= "server ">
<INPUT type= "text " name= "city ">
</form>
Head之间有一段js,其中有一个变量city,我用alert(city);可以得到值,但是怎么在js中把这个值赋给这个html控件?
document.all.city.value=city;试过了,不行。
<form id= "Form1 " method= "post " runat= "server "> 这个form也去掉了,不行。
method= "post " runat= "server "这句也去了,不行。
我js超级垃圾,求帮忙!!!
------解决方案--------------------------------------------------------
window.document.getElementsByName[0].value=city;
------解决方案--------------------------------------------------------
顶一下!
学习
------解决方案--------------------------------------------------------
document.form1.city.value=city;试过可行
------解决方案--------------------------------------------------------
<head>
<title> 无标题文档 </title>
<script language= "javascript ">
var city= "1111 ";
//alert(city);
document.form1.city.text=city;////////////////////这个搞不定。
</script>
</head>
<body>
<form id= "Form1 " runat= "server ">
<input name= "city " type= "text "/>
</form>
</body>
</html>
------解决方案--------------------------------------------------------
<head>
<title> 无标题文档 </title>
</head>
<body>
<form id= "Form1 " runat= "server ">
<input name= "city " type= "text "/>
</form>
</body>
</html>
<script language= "javascript ">
var city= "1111 ";
//alert(city);
document.all.city.value=city;////////////////////这个搞不定。
</script>
------解决方案--------------------------------------------------------
<form id= "Form1 " method= "post " runat= "server ">
<INPUT type= "text " name= "city " id= "city ">
</form>
------解决方案--------------------------------------------------------
呵呵,IE有问题。要不就是楼主太累了,眼花。
出去走走,回来就好了。
------解决方案--------------------------------------------------------
<script language= "javascript ">
var city= "1111 ";
alert(city);
var txt=document.all.item( 'city ');
txt.value=city;
</script>
这样绝对可以
------解决方案--------------------------------------------------------
<INPUT type= "text " name= "city " id= "city ">
注意要加上 id= "city "
脚本楼上的都对。