我正试图在wordpress的文章中加入javascripts。我以前只是将它添加到wordpress编辑器中的文章中,但我听说更好的方法是将它添加到主题文件夹中的js目录中,然后按下面的说明进行访问:
http://www.wpbeginner.com/wp-tutorials/how-to-move-javascripts-to-the-bottom-or-footer-in-wordpress/
我让它起作用了,当按下一个按钮时,就会发出警报。但是当我试图按如下的id得到一个元素时,却找不到它: document.getElementById('InOrCm').value = "in";
有什么建议吗?
谢谢你,山姆
更新:原来是一个html错误。下一步是使javascript在某些页面上工作。我一直试图用下面的代码来做这件事,但是我的wordpress,建议呢?
函数wpb_adding_scripts() { is_page(‘javascript-testing 2-2’){ wp_register_script('HeightComparisonTool',get_template_directory_uri()。‘/js/HeightcompisonTool.js’,'','1.1',真);wp_enqueue_script(‘HeightComparisonTool’;}} add_action(‘wp_enqueue_add_action’,'wpb_adding_scripts‘);
发布于 2016-02-06 17:53:18
我没听懂你问题的主要部分。还是让我试试:
document.getElementById('InOrCm').value = "in";这意味着您正在为id "InOrCm“的输入添加值。如果我得到你,那么你的语法是正确的。再检查一下你的“身份证”名。检查控制台输出。
document.getElementById('InOrCm').value = "in";
console.log(document.getElementById('InOrCm').value);以下是第二部分:
function wpb_adding_scripts() {
wp_register_script('HeightComparisonTool', get_template_directory_uri() . '/js/HeightComparisonTool.js','','1.1', true);
if(is_page( 'javascript-testing-2-2' )) {
wp_enqueue_script('HeightComparisonTool');
}
}
add_action( 'wp_enqueue_scripts', 'wpb_adding_scripts' );https://wordpress.stackexchange.com/questions/216895
复制相似问题