if(len(document.getElementById("servername").value)>16)
{
alert("不能超过16个字符");
}
/*
用途:检查输入字符串是否只由汉字、字母、数字组成
输入:
value:字符串
返回:
如果通过验证返回true,否则返回false
*/
function f_check_ZhOrNumOrLett(obj){ //判断是否是汉字、字母、数字组成
var regu = "^[0-9a-zA-Z\u4e00-\u9fa5]+$";
var re = new RegExp(regu);
if (re.test( obj.value )) {
return true;
}
return false;
}
{
alert("不能超过16个字符");
}
/*
用途:检查输入字符串是否只由汉字、字母、数字组成
输入:
value:字符串
返回:
如果通过验证返回true,否则返回false
*/
function f_check_ZhOrNumOrLett(obj){ //判断是否是汉字、字母、数字组成
var regu = "^[0-9a-zA-Z\u4e00-\u9fa5]+$";
var re = new RegExp(regu);
if (re.test( obj.value )) {
return true;
}
return false;
}
<td height="125" ><table width="92%" height="73" border="0" align="center" cellpadding="0" cellspacing="0" >
<tr>
<td width="52%" height="24" align="right" >
<input name="r1" type="radio" value="0" id="dhcp1" onclick="change(true)" <?php if ($dhcp=='1') echo 'checked="checked"';?>>
启用DHCP</td>
<td align="center" >
<input name="r1" type="radio" value="1" id="dhcp2" onclick="change(false)" <?php if ($dhcp=='0') echo 'checked="checked"';?> >
不启用DHCP</td> </tr>
<td colspan="2"><table width="100%" border="0" cellpadding="0" cellspacing="0" id="con">
<tr>
<td width="52%" height="24" align="right" >IP地址:</td>
<td width="48%" align="left" ><input name="ip" type="text" id="ip" value="<?php echo $ip?>" onKeydown="return check1(event)" <?php if ($dhcp=='1') echo "readOnly = 'readonly'";?>/></td>
</tr>
<tr>
<td width="52%" height="24" align="right" >子网掩码:</td>
<td width="48%" align="left" ><input name="netmask" type="text" id="netmask" value="<?php echo $netmask?>" onKeydown="return check2(event)" <?php if ($dhcp=='1') echo "readOnly = 'readonly'";?>/></td>
</tr>
<tr>
<td width="52%" height="24" align="right" >默认网关:</td>
<td width="48%" align="left" ><input name="gateway" type="text" id="gateway" value="<?php echo $gateway?>" onKeydown="return check1(event)" <?php if ($dhcp=='1') echo "readOnly = 'readonly'";?>/></td>
</tr>
</table></td><tr>
<td width="52%" height="24" align="right" >服务器别名:</td>
<td align="left" ><input name="servername" type="text" id="servername" onblur="alert(/^[\w\u4e00-\u9fa5]{0,16}$/.test(this.value))" value="<?php $servername = iconv("utf-8",'gb2312',$servername); echo $servername;?>" /></td>
</tr>
</table>
<table width="87%" height="24" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<td height="25" align="center" ><input name="tijiao" type="submit" class="btn" value="确 定" > </td>
</tr>
</table></td></FORM>
因为是onsubmit动作
如果 return false 就表示不执行 submit动作
true的话 就执行了啊
function check(){
if(document.getElementById("dhcp1").checked)
return true; var result = true;
var ip = document.admin.ip.value;
result = result && validate(ip);
var mask = document.admin.netmask.value;
result = result && validate(mask);
var gateway = document.admin.gateway.value;
result = result && validate(gateway); if(!result){
alert("请正确填写");
}
return result;
}