当前位置: 代码迷 >> JavaScript >> 怎么用javascript给text赋值
  详细解决方案

怎么用javascript给text赋值

热度:162   发布时间:2012-02-20 21:18:24.0
如何用javascript给text赋值
如下的一个input
<BODY>
<input   type= "text "   id= "a "   />
</BODY>

怎么在javascript   中给它赋值?

<script   language= "javascript ">

???
</script>


谢谢

------解决方案--------------------
赋什么值?输入框的内容? document.getElementById( "a ").value = ***;
------解决方案--------------------
document.getElementById( "xxx ").value;
或document.forms[0].xxx.value;
------解决方案--------------------
document.getElementById( "a ").value == " ";
------解决方案--------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN "
"http://www.w3.org/TR/html4/loose.dtd ">
<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
<title> 无标题文档 </title>

</head>

<body>
<form name= "form1 " method= "post " action= " ">
<input type= "text " name= "textfield ">
<script language= "javascript ">
document.getElementById( "textfield ").value= "ssss ";

</script>
</form>
</body>
</html>


再前面html还没生成,当然找不到,或写在onload函数里面
------解决方案--------------------
<input type= "text " name= "textfield " id= "textfield "> //加个id
------解决方案--------------------
<input type= "text " name= "textfield ">

document.getElementById是取id所以id不能为空;;
  相关解决方案