gpt4 book ai didi

javascript - 为什么我需要 jquery.min.js 而不是 jquery.js 脚本才能工作?

转载 作者:行者123 更新时间:2023-11-29 18:17:18 27 4
gpt4 key购买 nike

我是 Wordpress 的新手,这困扰了我一段时间。我想知道为什么我尝试包含的代码仅在我将 jquery.min.js 包含在“head”中时有效,尽管默认情况下子主题已经包含 jquery.js。下面我来解释一下。

我在“正文”末尾附近有一个脚本,用于指定画廊中的图像,以便在将鼠标悬停在图像上时不显示“固定它”按钮:

<script type="text/javascript">
$(document).ready(function() {
$(".tiled-gallery-item a img").attr("nopin","nopin");
});
</script>

只有当我将此代码包含在“head”中时,此代码才有效(即,nopin 属性被添加到相关的 img 标签中):

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js" type="text/javascript" /></script>

但是,从检查源代码来看,子主题似乎已经包含 jquery.js:

<script type="text/javascript" src="http://blog.froy.com/wp-includes/js/jquery/jquery.js?ver=1.10.2"></script>
<script type="text/javascript" src="http://blog.froy.com/wp-includes/js/jquery/jquery-migrate.min.js?ver=1.2.1"></script>

为什么需要 jquery.min.js?我是 Wordpress 的新手,它太令人困惑了。我认为 jquery.min.js 和 jquery.js 在功能上没有区别。什么是 jquery-migrate.min.js?

最佳答案

WordPress 带有内置的 jQuery,但默认情况下不会加载它。这可能是因为您的主题已在 functions.php

中应用 wp_enqueue_script('jquery');

替换此默认行为的一种解决方案是将此代码段添加到您的 functions.php:

function modify_jquery() {
if (!is_admin()) {
wp_deregister_script('jquery');
wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js', false, '1.8.1');
wp_enqueue_script('jquery');
}
}
add_action('init', 'modify_jquery');

此外,因为您使用的是 jQuery 版本 1.10.2jQuery migrate此处用于检测和恢复自 1.9 版起已弃用和删除的 API 或功能。

关于javascript - 为什么我需要 jquery.min.js 而不是 jquery.js 脚本才能工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21951765/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com