Home > Backend Development > PHP Tutorial > [php pro留言板相关]

[php pro留言板相关]

WBOY
Release: 2016-06-20 12:45:36
Original
955 people have browsed it

第一站:为留言板添加表单验证

jquery;https://github.com/posabsolute/jQuery-Validation-Engine

validationEngine,中文doc: http://code.ciaoca.com/jquery/validation_engine/


<a href="#" class=" icon user"></a><input type="text" class="validate[required]" name="name" placeholder="your name" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'your name';}" ><div class="clear"></div>
Copy after login

当placehoder和this.value值不一样时,jquery无法出现效果。

HTML 5 placeholder 属性

placeholder 属性提供可描述输入字段预期值的提示信息(hint)。

该提示会在输入字段为空时显示,并会在字段获得焦点时消失。


注意id和class的修改。


jQuery(document).ready(function()
Copy after login

这部分代码主要声明,页面加载后 “监听事件” 的方法。

使用document.ready()方法的执行速度比onload()的方法要快。

<link rel="stylesheet" href="css/validationEngine.jquery.css"><script src="js/jquery-1.7.2.js"></script> <script src="js/jquery.validationEngine-zh_CN.js"></script> <script src="js/jquery.validationEngine.js"></script> 	<script>		jQuery(document).ready(function(){			// binds form submission and fields to the validation engine			jQuery("#formID").validationEngine('attach', {				promptPosition : "topRight",				 autoPositionUpdate : true,				 showOneMessage: true,});		});            		function checkHELLO(field, rules, i, options){			if (field.val() != "HELLO") {				// this allows to use i18 for the error msgs				return options.allrules.validate2fields.alertText;			}		}	</script>
Copy after login


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template