JavaScript验证struts:html标签

xiaoxiao2026-03-11  11

页面代码如下:

<html:form action="" method="post" οnsubmit="return check()">

<table border="1" align="center" width="60%">   <tr>

        <td colspan="2" align="center" bgcolor="#9999FF">注册会员</td>

   </tr>  <tr>       <td align="right" bgcolor="#99FFFF">姓名</td>        <td><html:text property="user.u_name"/></td>  </tr>  <tr>      <td align="right" bgcolor="#99FFFF">性别</td>      <td><html:radio property="user.u_sex" value="1"/>男      <html:radio property="user.u_sex" value="0"/>女

      </td>  </tr>  <tr>

</table>

</html:form>

 

javascript验证代码可写为:

function check() {    if(document.getElementById("user.u_name").value=="")    {     alert("姓名不能为空!");     return false;    }

return true

}

 

如果想让单选按钮默认选中,可在整个页面代码的</html>后,加上如下javascript代码:

<script type="text/javascript">       document.all("user.u_sex")[0].checked=true;</script>

转载请注明原文地址: https://www.6miu.com/read-5045733.html

最新回复(0)