【发布时间】:2016-03-11 03:03:02
【问题描述】:
这是一个 WordPress 网站,我有一个模板可以在此 URL http://www.example.com/articles 的列表中呈现所有帖子。当用户单击帖子标题时,它会使用相同的模板但使用不同的 URL http://www.example.com/articles/?article_id=298 加载帖子的内容。我不知道如何在页面加载帖子内容后显示警报。我试过setTimeout,$(document).ready,$(window).load,window.onload=funtion(),现在$(document).on("pagecontainerload",function()。
JQuery/JavaScript
$('a.open-alert').click(function() {
$(document).on("pagecontainerload",function(){
window.alert('hey');
});
});
HTML
<?php
$tearsheet = get_query_var('article_id');
if($tearsheet != '') {
echo 'there is something here';
} else {
$args = array(
'post_type' => 'post',
'posts_per_page' => -1,
);
$query = new WP_Query( $args );
if($query->have_posts()) :
while($query->have_posts()) :
$query->the_post();
?>
<div>
<?php $id = get_the_ID(); ?>
<?php $title = get_the_title(); ?>
<a class="open-alert" href="<?php bloginfo('url'); echo '/find-articles/?article_id='.$id; ?>"><?php echo $title; ?></a>
</div>
<?php
endwhile;
endif;
}
?>
【问题讨论】:
-
当打开警报链接被点击时,整个页面是否重新加载(使用 href-attribute 中的 URL)?
-
是的,整个页面都重新加载了。
标签: javascript jquery