我试图在通过id调用时默认打开一个模式框。
例如,如果我输入urlwww.mysite.com#post-28
(#post28是帖子的ID)
我将带着莫阿达尔盒子和28后的内容着陆。
为此,我一直在使用以下jquery(iattach代码的基本版本):
<script>
jQuery(function ($) {
function popModal() {
{ alert("Your book is overdue.")
};
}
var hash = window.location.hash;
if (hash.substring(1) == \'post-<? the_ID(); ?>\') {
popModal();
}
});
</script>
当im动态调用时,它不工作
post-<? the_ID(); ?>
但是,如果改用此代码:
<script>
jQuery(function ($) {
function popModal() {
{ alert("Your book is overdue.")
};
}
var hash = window.location.hash;
if (hash.substring(1) == \'post-17\') {
popModal();
}
});
</script>
(17号岗位为岗位ID),
它确实有效。
我相信这个问题与我如何称呼这个职位有关<? the_ID ?>
任何帮助都将是难以置信的!
谢谢
---编辑---
我这样称呼我的JS,似乎崩溃了:
add_action( \'wp_enqueue_scripts\', \'themeeo_scripts\' );
function themeeo_scripts() {
// Load stylesheets
wp_register_style(\'theme-style\', get_template_directory_uri() . \'/css/style.css\',array(\'bootstrap\'));
wp_register_style(\'font-awesome\', get_template_directory_uri() . \'/css/font-awesome.min.css\');
wp_register_style(\'bootstrap\', get_template_directory_uri() . \'/css/bootstrap.min.css\');
wp_register_style(\'owl-carousel\', get_template_directory_uri() . \'/css/owl.carousel.css\');
wp_register_style(\'tether\', get_template_directory_uri() . \'/css/tether.min.css\');
wp_register_style(\'responsive-styles\', get_template_directory_uri() . \'/css/responsive.css\',array(\'bootstrap\'));
wp_register_style(\'custom-style\', get_template_directory_uri() . \'/css/custom.css\',array(\'bootstrap\'));
// wp_enqueue_style(\'tether\');
wp_enqueue_style(\'bootstrap\');
wp_enqueue_style(\'font-awesome\');
wp_enqueue_style(\'style-dynamic\');
wp_enqueue_style(\'responsive-styles\');
wp_enqueue_style(\'theme-style\');
wp_enqueue_style(\'custom-style\');
if ( is_singular() && comments_open() && get_option( \'thread_comments\' ) ) {
wp_enqueue_script( \'comment-reply\' );
}
// Load jQuery scripts
wp_register_script(\'jquery\', get_template_directory_uri() . \'/js/jquery.js\', array(\'jquery\'));
wp_register_script(\'custom\', get_template_directory_uri() . \'/js/jquery.custom.js\', array(\'jquery\'));
wp_register_script(\'bootstrap\', get_template_directory_uri() . \'/js/bootstrap.min.js\', array(\'jquery\'));
wp_register_script(\'owl-carousel\', get_template_directory_uri() . \'/js/owl.carousel.min.js\', array(\'jquery\'));
wp_register_script(\'tether\', get_template_directory_uri() . \'/js/tether.min.js\', array(\'jquery\'));
wp_register_script(\'velocity\', get_template_directory_uri() . \'/js/velocity.js\', array(\'jquery\'));
wp_register_script(\'velocityui\', get_template_directory_uri() . \'/js/velocity.ui.js\', array(\'jquery\'));
wp_register_script(\'helium-parallax-js\', get_template_directory_uri() . \'/js/helium.parallax.js\', array(\'jquery\'));
wp_register_script(\'urlhash\', get_template_directory_uri() . \'/js/urlhash.js\', array(\'jquery\'));
wp_localize_script( \'custom\', \'menuToggleText\', array(
\'open\' => esc_html__( \'Open child menu\' ),
\'close\' => esc_html__( \'Close child menu\' ),
) );
wp_enqueue_script(\'helium-parallax-js\');
wp_enqueue_script(\'jquery\');
wp_enqueue_script(\'tether\');
wp_enqueue_script(\'bootstrap\', \'\', \'\', \'\', true);
wp_enqueue_script(\'owl-carousel\', \'\', \'\', \'\', true);
wp_enqueue_script(\'tether\', \'\', \'\', \'\', true);
wp_enqueue_script(\'custom\', \'\', \'\', \'\', true);
wp_enqueue_script(\'skrollr.js\', \'\', \'\', \'\', true);
wp_enqueue_script(\'velocity\', \'\', \'\', \'\', true);
wp_enqueue_script(\'velocityui\', \'\', \'\', \'\', true);
wp_enqueue_script( \'urlhash\', get_template_directory_uri() . \'/js/urlhash.js\', array( \'jquery\' ) );
if ( is_single() ){
$localization = array(
\'post_id\' => get_the_ID(),
);
wp_localize_script( \'urlhash\', \'localized_object\', $localization );
}
}