1.可以通过document.form集合来引用表单,例如一个name为“myform1”的表单可以用如下语句来获得:
document.forms["myform1"]
其中html部分为:
<form method="post" name="myform1" action="aa.jsp"/>
2.文本框input,可以通过maxlength属性控制字符个数;
但是textarea并没有该属性。对于textarea,我们可以通过以下方式来限制长度,下例中没有设置cols,rows,请自行设置。
<textarea maxlenth="50" οnkeypress="return lessthan(this)"/>
script中定义lessthan函数如下:
function lessthan(oTextarea)
{
oTextarea.value.length<oTextarea.getAttrubute("maxlenth");
}
3.鼠标经过文本框时,自动聚焦并选中内容,以方便 用户操作:
<input type="text" value="name:" οnmοuseοver="this.focus();" οnfοcus="this.select();"/>