javascript验证 求解
今天用javascript验证text中内容是否为空,验证一直不出现提示,请赐教
<script type ="text/javascript" language ="javascript" >
function checkname()
{
var na= document.getElementById["d1"];
var name = document.form1.text1.value;
if (name.length==0)
{
na.value = "用户名不能为空";
return true;
}
}
</script>
<body>
<form id="form1" runat="server">
<span>用户名:</span>
<input id="Text1" type="text" onblur ="return checkname() "/><div id="d1"style="display:inline ">
</div>
</form>
</body>
------解决方案--------------------
两个错误
1,document.getElementById[" 方括号应该圆括号
2, na.value
na 是div,要显示的话用 innerHTML