Home > Web Front-end > JS Tutorial > What to do if jquery cannot be referenced

What to do if jquery cannot be referenced

藏色散人
Release: 2021-01-25 09:59:53
Original
3400 people have browsed it

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.

What to do if jquery cannot be referenced

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>
Copy after login

3. jquery verification

<script type="text/javascript">
    $("#dataForm").validate( {//提交表单时,开始验证
                rules : {
                    &#39;name&#39; : {
                        required : true
                    },
                    &#39;dataYear&#39; : {
                        required : true
                    }
                },
                messages : {
                    &#39;name&#39; : {
                        required : "请输入名称"
                    },
                    &#39;dataYear&#39; : {
                        required : "请输入时间"
                    }
                },
                focusInvalid : false,
                onkeyup : false,
                errorPlacement : function(error, element) {
                    error.appendTo(element.parent());
                }
            });
</script>
Copy after login

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!

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