首页 > 解决方案 > 使用 jquery 脚本添加操作时如何修复 (T_CONSTANT_ENCAPSED_STRING)

问题描述

我正在尝试从头开始创建一个 wordpress 主题,但是在添加时

add_action('wp_enqueue_scripts', 'jquery');

在我得到的页面上弹出我的 js 脚本警报

解析错误:语法错误,意外'',1,真);' (T_CONSTANT_ENCAPSED_STRING),期待 ')'

对于那条线

function include_jquery() {
  wp_deregister_script('jquery');
  wp_enqueue_script('jquery', get_template_directory_uri() . '/js/jquery3.3.1.min.js, '', 1, true);
  add_action('wp_enqueue_scripts', 'jquery');
}
add_action('wp_enqueue_scripts', 'include_jquery');

我希望代码能够从我的 js 文件中显示我的警报。

$(document).ready(function() {  
  alert('test');
})

标签: phpwordpress

解决方案


错字。改变

wp_enqueue_script('jquery', get_template_directory_uri() . '/js/jquery3.3.1.min.js, '', 1, true);

wp_enqueue_script('jquery', get_template_directory_uri() . '/js/jquery3.3.1.min.js', '', 1, true);

推荐阅读