javascript - 我的 wordpress 代码中是否有任何 jquery 冲突?
问题描述
我有一个 wordpress 页面,我想在其中使用数据值检查复选框中的类别。在这种情况下“公告”
这个脚本在 codepen 上运行得很好,但在 wordpress 上不行。以下是我放在 wordpress 页面上的所有内容。
jQuery(document).ready(function() {
var input = $('input[data-value="Announcement"]')
input.focus();
input.select();
input.prop('checked', true);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js">
</script>
<input type="checkbox" id="test" name="category[]" data-wpt-type="checkbox" data-wpt- id="test" data-wpt- name="category[]" value="1" data-parent="-1" data-value="Announcement" class="wpt-form-checkbox form-checkbox checkbox">
<input type="checkbox" id="test2" name="category[]" data-wpt-type="checkbox" data-wpt- id="test2" data-wpt- name="category[]" value="2" data-parent="-1" data-value="Story" class="wpt-form-checkbox form-checkbox checkbox">
这是一个 jquery 问题/冲突吗?是主题冲突,还是代码错误?
jQuery.Deferred exception:
b(...).not(...).filter(...).mediaelementplayer is not a function
a@http://localhost/wordpress2018/wp-includes/js/mediaelement/wp-
mediaelement.min.js?ver=4.9.8:1:634 g/</k<@https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js:2:
30262
undefined jquery.min.js:2:31515
jQuery.Deferred exception: jQuery(...).css(...).mCustomScrollbar is
not a
function Init_BodyConv@http://localhost/wordpress2018/wp-
content/plugins/um-messaging/assets/js/um-messaging.js?ver=4.9.8:36:2
@http://localhost/wordpress2018/wp-content/plugins/um-
messaging/assets/js/um-messaging.js?ver=4.9.8:115:2 j@https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js:2:2994 g/</k<@https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js:2:30262
解决方案
Wordpress 主题通常使用jQuery.noConflict()这使得全局$
未定义以防止与其他可能使用的库发生冲突$
尝试改变
jQuery(document).ready(function() {
至
jQuery(document).ready(function($) {
// ^^
这将$
在ready
回调中公开
推荐阅读
- python - Django:“is_admin”列中的空值违反非空约束
- python - matplotlib:如何创建原始后端
- python - 对 postgresql 进行 1 个查询还是多个查询更好?
- java - 关于 HashMap#treeifyBin 的困惑
- c++ - 如果用户输入的输入大于 char 数组,cin.getline 会跳过输入提示
- python-3.x - 我在列中有一个值作为平装本,– 2016 年 3 月 10 日,我只想从中获取月份和年份。我应该如何在 python 中做到这一点
- logging - kube-scheduler 产生巨大的日志文件
- java - 如何使用流从具有条件的对象列表中获取子列表,例如对象的对象属性之和小于或等于阈值?
- python - 这段代码有什么问题?我收到名称错误
- python - 使用 QtWebdriver 选择一个 QComboBox