javascript wordpress 联系表 7 和自定义 jQuery 冲突
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18496495/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
wordpress contact form 7 and custom jQuery conflicting
提问by addy88
I am using contact form 7 on wordpress and untill today I have experienced a problem. I have come to learn that it is a jQuery conflict. I find the problem only occurs in chrome works fine in firefox.
我在 wordpress 上使用联系表 7,直到今天我遇到了一个问题。我了解到这是一个 jQuery 冲突。我发现这个问题只发生在 chrome 在 Firefox 中工作正常。
I have some custom jQuery which I placed in which can be seen below.
我有一些自定义的 jQuery 放在里面,如下所示。
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script type="text/javascript">
jQuery(document).ready( function(){
var map = [ '11.99', '£13.99', '£14.99' ];
jQuery('#payslips-required').change(function(){
var o = parseInt($(this).val()) < 3 ? jQuery(this).val()-1 : 2;
jQuery('#price').val(map[o]).addClass('hidden');
});
});
</script>
With the above in place the ajax does not work on contact form 7 which I require. When I remove
有了上面的内容,ajax 就不能在我需要的联系表格 7 上工作了。当我删除
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
It works but the custom jQuery does not. I need both to run.
它有效,但自定义 jQuery 无效。我需要两个都跑。
This is the error I get when I inspect it in chrome
这是我在 chrome 中检查时得到的错误
Uncaught TypeError: Object [object Object] has no method 'on'
Any suggestions?
有什么建议?
采纳答案by Joe
Try removing the call to the old JQUERY file. Then move your custom lines to be below where Wordpress is calling the JQUERY file. Most likely your is running before the JQUERY js file is loaded.
尝试删除对旧 JQUERY 文件的调用。然后将您的自定义行移动到 Wordpress 调用 JQUERY 文件的下方。您很可能在加载 JQUERY js 文件之前运行。