我對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