多个javascript文件冲突

时间:2015-11-28 00:43:33

标签: javascript html forms conflict

我目前正在制作一个表单,用于将新成员上传到网页。我使用JotForm构建了表单,其中包含用于控制样式的js文件(隐藏/显示字段,需要变为红色的字段等)。

这个表单的js本身运行良好,但我还包括一个图片裁剪/上传作为额外的。当我单独在一个单独的网页上测试它时,这也有效,但现在结合表格,js冲突,我不知道如何阻止它。 我的脚本头部分如下所示:

<!-- Jotform js -->
<script src="https://cdn.jotfor.ms/static/prototype.forms.js" type="text/javascript"></script>
<script src="https://cdn.jotfor.ms/static/jotform.forms.js?3.3.10027" type="text/javascript"></script>
<script type="text/javascript">
    JotForm.setConditions([{"action":[{"id":"action_0_1448505712729","visibility":"Show","isError":false,"field":"77"}],"id":"1448505521328","index":"0","link":"Any","priority":"0","terms":[{"id":"term_2_1448505712729","field":"68","operator":"equals","value":"Librarian","isError":false},{"id":"term_1448505745204","field":"68","operator":"equals","value":"Social Sec.","isError":false},{"id":"term_1448505752197","field":"68","operator":"equals","value":"Press & Publicity","isError":false},{"id":"term_1448505759596","field":"68","operator":"equals","value":"Webmaster","isError":false},{"id":"term_1448505768860","field":"68","operator":"equals","value":"Tour Manager","isError":false},{"id":"term_1448505778873","field":"68","operator":"equals","value":"Merch Rep.","isError":false},{"id":"term_1448505785856","field":"68","operator":"equals","value":"Ordinary Member","isError":false}],"type":"field"}]);
    JotForm.init(function(){
        setTimeout(function() {
            $('input_76').hint('e.g. 1st, 2nd, 3rd');
        }, 20);
        JotForm.clearFieldOnHide="disable";
        JotForm.onSubmissionError="jumpToSubmit";
    });
</script>
<!-- Image cropper js -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script src="js/jquery.cropit.js"></script>
<script src="js/index.js"></script>

因为prototype.forms.js和jotform.forms.js首先出现,所以它们似乎可以工作,而图像裁剪器却没有。 如果我把图像裁剪器文件放在第一位,反过来就发生了图像裁剪器,但是其他的javascript没有。

在阅读完这篇文章后,很多人都在谈论这是jQuery冲突,但我并不完全确定问题/解决方案是什么。我想要的只是两个功能同时工作。

所有帮助表示感谢,谢谢。

来源(仅限图片裁剪器):http://concert-band.co.uk/new/Forms/index2.php

来源(仅限表单验证):http://concert-band.co.uk/new/Forms/index3.php

1 个答案:

答案 0 :(得分:0)

稍微有点我的错,因为我意识到与index.jsjquery.cropit.js没有冲突,实际上我的<body>底部有一些嵌入式jquery,我已经忘记了。我现在以正常的方式实现了jQuery.noConflict(),它运行正常。谢谢你的帮助。