【发布时间】:2016-12-01 18:33:53
【问题描述】:
如果只满足一个 php 条件,你如何运行 javascript?我试图仅在$page_count 是<= 1 时显示一个弹出窗口。 php 很好并且可以正常运行,因为我已经使用简单的 echo 对其进行了测试,只有当我尝试否定 javascript 的运行时,如果 $page_count 超过 2,它仍然可以运行。
有没有通用的方法来解决这个问题?
if ($page_count <= 1) {
$setup_popup =
'<div id="status-popup">
<div id="status-popup-container" class="total-center">
<a class="popup-close" data-popup-close="popup-1" href="#">Close</a>
</div>
</div>'
;
}
else {
$setup_popup = NULL;
}
Javascript
$('#status-popup').fadeIn(350);
$('[data-popup-close]').on('click', function(e) {
var targeted_popup_class = jQuery(this).attr('data-popup-close');
$('#status-popup').fadeOut(350);
$('body').css('overflow', 'auto');
e.preventDefault();
});
【问题讨论】:
-
为什么不直接将计数器作为变量传递,让 JS 决定呢?
-
页面没有
status-popup,js怎么运行? -
@ssube 不知道怎么做。
-
对不起大家,我使用了错误的 php 变量。您的解决方案确实对我有所帮助,因此对于给您带来的不便,我深表歉意。
标签: javascript php if-statement