首页 > 解决方案 > 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>

标签: jquerywordpress

解决方案


推荐阅读