Solutions to the inability to reference jquery: 1. Check and modify the reference path; 2. Because the html element does not meet the standards, just place the jquery method below the form.
The operating environment of this tutorial: windows7 system, jquery1.2.6 version, DELL G3 computer.
Recommended: jquery video tutorial
Problem description: jquery.js cannot be referenced in the project or cannot be used normally after being referenced.
Solution:
Check and modify the html elements; the reasons found on the Internet for not working properly are:
1. Wrong reference path
2. The html element does not meet the standards, eg: div is nested inside span, and form is nested within form
After checking, my path is correct and there is no nesting error. The final solution is to place the jquery method below the form.
Because jquery was rarely used before, here is a record of how to use jquery verification. Of course, specific problems will be solved on a case-by-case basis.
1. Introduction of jquery.js and jquery.validate.js
2. Contents in the form
<STYLE type=text/css> input.error { border: 2px dashed red; } LABEL { color: red; } textarea.error { border: 2px dashed red; } </STYLE> <form id="dataForm" name="dataForm" action="import" method="post"> <table boder="0"> <tr><td>名称:<input type="text" id="name" name="name" ></td></tr> <tr><td>年份:<input type="text" id="dataYear"name="dataYear"/>*</td></tr> <tr><td><input type="submit" value="数据入库"/></td></tr> </table> </form>
3. jquery verification
<script type="text/javascript"> $("#dataForm").validate( {//提交表单时,开始验证 rules : { 'name' : { required : true }, 'dataYear' : { required : true } }, messages : { 'name' : { required : "请输入名称" }, 'dataYear' : { required : "请输入时间" } }, focusInvalid : false, onkeyup : false, errorPlacement : function(error, element) { error.appendTo(element.parent()); } }); </script>
The above is the detailed content of What to do if jquery cannot be referenced. For more information, please follow other related articles on the PHP Chinese website!