javascript - jQuery 代码搞乱了我其余的 JavaScript 代码

标签 javascript jquery html jquery-plugins

我的整个 JavaScript 运行完美,没有任何错误,但是当我尝试使用 jQuery 时,我遇到了大量的各种错误: enter image description here

这是我的 jQuery 代码(它使用了 jQuery 插件,但在使用插件之前我已经使用了一些纯 jQuery 代码并得到了相同的结果。此代码位于 <script> 内):

$(function() {
                $("#mailSender").validate({
                    rules: {
                      email: {
                       required: true,
                       email: true
                     }
                   }
                    messages: {
                     email : {
                       required: "This field is required.",
                       email: "Please enter a valid email address."
                      }
                    }
                  });
                });

这些是scrldown() , bordcol()bordcolBlack() “未定义”的函数:

function scrldown() {
                var navv = document.getElementById('nav_inn'),
                style = window.getComputedStyle(navv),
                top = style.getPropertyValue('top');
                if (top === "-180px") {
                    TweenMax.to(".nav_in", .4, {top:"20"});
                    TweenMax.to([".trii, .trii_h"], .2, {rotation:"180"});
                }
                else {
                    TweenMax.to(".nav_in", .4, {top:"-180px"});
                    TweenMax.to([".trii, .trii_h"], .2, {rotation:"0"});
                }
            }

相应的 HTML( <a> 标签最初与其余标签具有相同的 href="javascript:scrldown()" 而不是 onclick ,但这两种方法都可以在没有 jQuery 的情况下工作):

<a href="javascript:void(0)" onclick="scrldown()">
                    <img src="../images/scrl_tri.png" id="tri" height="21px;" class="trii" />
                    <img src="../images/scrl_tri_hov.png" id="tri" height="21px" class="trii_h" />
                </a>
<span class="shop"><a href="javascript:scrldown()">Shop</a></span>
<span class="gallery"><a href="javascript:scrldown()">Gallery</a></span>

<小时/> <div id="wrap-left" onmouseover="bordcol()" onmouseout="bordcolBlack()">
并且(map-canvas是其中的一个div):

function bordcol() {
                document.getElementById("map-canvas").style.borderTop="1px solid #F8CE26";
            }

            function bordcolBlack() {
                document.getElementById("map-canvas").style.borderTop="1px solid #9F9F9F";
            }

<小时/> 这是“src<script>位于 <header> :

<script src="../js/jquery.js"></script>
<script src="../js/jquery_validate/dist/jquery.validate.js"></script>

我还有一些其他插件,但没有一个依赖于 jQuery,jQuery 也是第一个导入的。
顺便说一句,如果重要的话,该插件是 jQuery 验证插件

<小时/> 抱歉写了这么多代码,但我真的希望你们能帮助我解决这个问题(当然,除非我错过了一些非常愚蠢的东西。然后指出来)。
应该指出的是,我对 jQuery 的了解非常有限,我可能会遗漏一些对您来说非常明显且愚蠢的事情,所以即使您看不到立即的答案,也请评论一些简单的 jQuery 规则,这些规则可能会在这里不可见,但很重要/至关重要。
谢谢!

最佳答案

您的代码中有拼写错误,rulesmessages 之间缺少逗号 (,),应该是:

$("#mailSender").validate({
    rules: { ... }, // this comma is missing
    messages: { ... }
});

关于javascript - jQuery 代码搞乱了我其余的 JavaScript 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31614725/

相关文章:

javascript - Google API获取刷新 token : Uncaught ReferenceError: offline is not defined

javascript - 显示随机 div onclick

javascript - 通过运行 java selenium 测试来覆盖 JS 组件的代码覆盖率

jquery - 如何将 html 选择选项返回到其原始顺序?

php - 使用 PHP 为数据库中的每一行提供唯一的页面

javascript - bxslider 在移动设备中缩放

javascript - 在 Canvas 中填充一部分绘制的图像

javascript - 为什么 getElementsByClassName 不起作用而 getElementById 起作用?

html - Angular.js Controller 无法设置属性

html - "overflow: hidden;"用于百分比大小的表格单元格