可以将jquery插入php文件吗?

时间:2019-12-10 12:09:56

标签: php jquery html wordpress

我有以下.php文件:

<div class="excerpt">
  <?php get_the_excerpt();?>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
  $(document).ready(function() {
    $(".excerpt").hide();
  });
</script>

我想通过jQuery隐藏div类“摘录”。不幸的是,代码没有执行任何操作,而且我不明白我哪里出错了。甚至有可能在php中使用jQuery吗?

1 个答案:

答案 0 :(得分:0)

默认情况下,

标识符$通常不会在像cms这样的wordpress中启用

您必须使用标识符jQuery

为了使标识符$有效,您可以尝试

(function($){
    // inside this scope, $ can be used
    $(document).ready(function(){

        // other scripts

    });
})(jQuery);