我的页面出现错误,我相信是因为 php if 语句没有显示条件表。
错误:TypeError:document.getElementById("count2") 为 null 源文件:https ://www.mysite.com/js/clocktimer.js 行:43
我有一个条件语句:
<?php if ( $this->session->userdata('days_to_challenge') > 0 ) : ?>
<table id="mytable" border="0">
<tr>
<td align="center" colspan="4"><div class="numbers" id="count2" style="padding: 10px; "></div></td>
</tr>
<?php endif; ?>
我的js代码导致错误:
document.getElementById('count2').style.display="block";
document.getElementById('count2').style.width="390px";
...
挑战的天数已经归零,即。挑战已经开始,所以我没有显示倒计时表。
防止此类错误的最佳方法是什么?