我如何使用Window.Onload事件? [英] How Do I Use Window.Onload Event?
本文介绍了我如何使用Window.Onload事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试使用minlength进行验证。代码适用于jsfiddle但它在我的html页面上不起作用。
JSfiddle
完整代码:
< < span class =code-leadattribute> html >
< head >
< / head >
< body >
< script type = text / javascript src = // ajax.googleapis.com/ajax/libs/jquery/1.8。 3 / jquery.min.js > < / script >
< script type = text / javascript >
window.onload = function( ){
$(#form)。validate({
规则:{
'phonenumber':{
required:true,
minlength:10
}
}
});
});
< / script >
< 表格 action = order.php 方法 = post id = 表单 >
您的电话号码:
< 输入 名称 = phonenumber type = text id = ' phonenumber' maxlength = 10 自动填充 = off onkeypress =' 返回事件.charCode> = 48&& event.charCode< = 57' 占位符 = phonenumber >
< 输入 type = 提交 < span class =code-keyword> / >
< / form >
< / body >
< / html >
解决方案
(#form)。验证({
规则:{
'phonenumber':{
required:true,
minlength:10
}
}
});
});
< / script >
< 表格 action = order.php 方法 = post id = 表单 >
您的电话号码:
< 输入 名称 = phonenumbertype = text id = ' phonenumber' maxlength = 10 自动填充 = off onkeypress =' 返回事件.charCode> = 48&& event.charCode< = 57' 占位符 = phonenumber >
< 输入 type = 提交 < span class =code-keyword> / >
< / form >
< / body >
< / html >
> <块引用>考虑你在小提琴中工作的内容:
您需要为JQuery的验证库添加脚本引用(您可以使用以下(在CDN上)):
http://ajax.aspnetcdn.com/ajax/jquery.validate/1.13.1/jquery.validate.min.js
此外,您还需要从脚本中删除额外的)
。 />
希望这会有所帮助。
Am trying to do a validation using minlength. The code works on jsfiddle but it doesn't work on my html page.
JSfiddle
Full code:
<html>
<head>
</head>
<body>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
window.onload = function(){
$("#form").validate({
rules: {
'phonenumber': {
required: true,
minlength: 10
}
}
});
});
</script>
<form action="order.php" method="post" id="form">
Your phone number :
<input name="phonenumber" type="text" id='phonenumber' maxlength="10" autocomplete="off" onkeypress='return event.charCode >= 48 && event.charCode <= 57' placeholder="phonenumber">
<input type="submit" />
</form>
</body>
</html>
解决方案
("#form").validate({ rules: { 'phonenumber': { required: true, minlength: 10 } } }); }); </script> <form action="order.php" method="post" id="form"> Your phone number : <input name="phonenumber" type="text" id='phonenumber' maxlength="10" autocomplete="off" onkeypress='return event.charCode >= 48 && event.charCode <= 57' placeholder="phonenumber"> <input type="submit" /> </form> </body> </html>
Considering what you have working in the fiddle:
You need to add a script reference for JQuery's validation library (you may use following (on a CDN)):
http://ajax.aspnetcdn.com/ajax/jquery.validate/1.13.1/jquery.validate.min.js
Also, you need to remove an extra)
from your script.
Hope this helps.
这篇关于我如何使用Window.Onload事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文