我对PHP相当陌生,所以原谅缺乏知识。在functions.php中导入javascript不起作用
目前我正在尝试添加一个小的JavaScript文件到儿童主题。我已经将下面的代码添加到孩子的functions.php文件中。
if (is_page_template('page-templates/edit-profile.php')) {
function add_form_unlock() {
wp_enqueue_script(
'form_unlock',
$get_stylesheet_directory_uri() . '/js/form_unlock.js',
array('jquery'),
'1.1',
true
);
}
add_action('wp_enqueue_scripts', 'add_form_unlock');
}
我的JavaScript
var pass1 = "QuL7eD";
function check(){
var pass2 = document.getElementById("password").value;
if (pass1 == pass2) {
document.getElementById("button").disabled = false;
document.getElementById("test").disabled = false;
}
}
我已经运行成功那么清楚它只是没有在WordPress模板运行的test.html文件中的JavaScript。
任何帮助将是伟大的!
只是作为小费,你应该*从未*有存储在JavaScript这样的地方,用户可以轻松地查看源密码和直接从你的代码中读取它。 –
'$ get_stylesheet_directory_uri()'?变量函数?你确定不应该只是'get_stylesheet_directory_uri()'?没有'$'? –
密码仅用于测试,但是,谢谢Nick。而马克你对这个$是正确的。谢谢! – Tyler