jquery - WordPress JQuery .. WordPress 忽略了我的代码
问题描述
抱歉,如果这是一个愚蠢的问题,但我如何让 WordPress 真正查看我的代码!它完全忽略它,只是遵守 HTML。
就好像 jQuery 根本不存在一样。我确定我在 jQuery 代码中犯了一些错误,但我没有真正的想法,因为我什至无法测试它。
jQuery
我已经阅读了我所做的需要更改的“$” 。我已经在 public_html 文件中安装了 _js 并且还在那里添加了 jQuery 文本以防万一。
我还在functions.php
这里根据其他人的建议添加了以下内容:
function add_my_script() {
wp_enqueue_script('custom-script', get_template_directory_uri() .'/_js/meet-the-team.js', array('jquery'));
}
add_action( 'wp_enqueue_scripts', 'add_my_script' );
这是被忽略的代码:
<script src="../_js/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('#gallery img').each(function(i) {
var imgFile = jQuery(this).attr('src');
var preloadImage = new Image(); =
var imgExt = /(\.\w{3,4}$)/;
preloadImage.src = imgFile.replace(imgExt, '_h$1');
jQuery.noConflict();
jQuery(this).hover(
function() {
jQuery(this).attr('src', preloadImage.src);
},
function() {
var currentSource = jQuery(this).attr('src');
jQuery(this).attr('src', imgFile);
}); // end hover
}); // end each
//insert new programming below this line
jQuery('#gallery a').click(function(evt) {
evt.preventDefault();
var imgPath = jQuery(this).attr('href');
var oldImage = jQuery('#photo img');
var newiamge = jQuery('<img src= "' +../wp-content/uploads/2019/11/slide1.png + '">');
//make new image invisible
newImage.hide();
//add to the #photo div
jQuery('#photo').prepend(newImage);
//fade in new image
newImage.fadeIn(1000);
//fade out old image and remove from DOM
oldImage.fadeOut(1000, function() {
jQuery(this).remove();
});
}); // end click
jQuery('#gallery a:first').click();
}); // end ready
</script>
解决方案
推荐阅读
- angularjs - 玉模板中的ng-repeat注释掉了
- c++ - C++ 按值排序 unordered_map 或 map
- bash - 如何从批处理脚本中的文本文件中找到以下文本?
- github - 神秘的 Azure Pipelines 定义出现在我的 github 存储库中
- python - 如何用python获取网页窗口数据?
- python - Extracting unique value rows from a table into new data frame
- python - Jupyter notebook 运行等待功能
- linux - 使用 /proc/kpageflags 确定页面是否脏
- r - R:使用 regr.svm 任务预测 mlr 中的新因子水平
- google-sheets - 如何在 Google 工作表单元格中将函数引用为文本