【发布时间】:2015-04-30 11:49:00
【问题描述】:
所以我为 wordpress 网站创建了一个插件。在其中,我想调用一个位于我刚刚入队的文件中的 JavaScript 函数(带有字符串)。但什么都没有发生。有人可以看到错误吗?
function tsd_getscript() {
if(is_single()){
wp_enqueue_script( 'imagefix-js', get_template_directory_uri() . '/js/imagefix.js', array(), '1.0.0', true);
echo "<script>alertText('TEST');</script>";
}
}
add_action( 'wp_enqueue_scripts', 'tsd_getscript' );
在 imagefix.js 中,代码如下:
function alertText(string){
alert(string);
}
我得到的只是控制台说 alertText 未定义。所以它就像它根本不加载js文件..我在这里遗漏了一些明显的东西吗?
编辑:所以由于未定义我检查了源代码并且警报代码加载在头部但脚本在正文中,我如何在脚本加载后完成警报?
【问题讨论】:
标签: javascript php wordpress plugins