我是javascript的初学者。现在,我正在尝试制作一个表格,以发布回服务器。有一些包含IP地址的“输入”,应在提交之前进行验证。现在,我已经完成了一个很好的javascript函数。但是现在我正在尝试将此功能添加到jquery选择中。只是混淆如何做。
这是我的验证javascript代码。
function ValidateIPaddress(Ipfield)
{
IpAddr=Ipfield.value;
var ipformat = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
if(!IpAddr.match(ipformat))
return true;
else
return false;
}
现在这就是我实现此验证的方式。
<input type= "text" name= "LocalIP" style= "margin-right:10px " value="192.168.1.193" class="ip" onfocusout="ValidateIPaddress(document.getElementById('LocalIp'))" id="LocalIp" > Remote VIP Address :
<input type= "text" name= "RemoteVIPAddr" style= "margin-right:10px" value="234.5.6.7" class="ip" onfocusout="ValidateIPaddress(document.getElementById('RemoteIp'))" id="RemoteIp" >
Remote VIP Port :
<input type= "text" name= "RemoteVIPPort" style= "margin-right:10px" value="5004" class="ip" onfocusout="ValidatePort(document.getElementById('RemoteVIPPort'))" id="RemoteVIPPort">
现在,我想使用jquery选择来始终检查是否有一些无效的输入。就是这样,但是有我自己的设计功能。
$("input.ip:visible").filter(function() { return this.ValidateIPaddress === true }).addClass("invalid");
有人有想法吗?
您不是ValidateIPAddress
在调用过滤器函数,而是在测试DOM元素是否具有名为的非空属性ValidateIPAddress
。它应该是:
$("input.ip:visible").filter(function() {
return ValidateIPAddress(this);
}).addClass("invalid");
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句