首页 新闻 赞助 找找看

Uncaught TypeError: Cannot set property 'innerHTML' of null

0
悬赏园豆:10 [已解决问题] 解决于 2016-04-07 20:04

问题简单描述:

<div class="helloTime">
      <ul class="hello_le">
       <li class="hello_le2">
        <c:if test="${user.identityId == 1}">
         <p class="hello_time">HI 厂家您好</p>
         <span class="welc">欢迎来到俱合网<span>
         </c:if>
        <c:if test="${user.identityId == 2}">
         <p class="hello_time">HI 买家您好</p>
         <span class="welc">欢迎来到俱合网<span>
         </c:if>
        <c:if test="${user.identityId == null}">
         <p class="hello_time" id="overTime">a</p>
         <span class="welc">欢迎来到俱合网<span>
         </c:if>
       </li>
       <li  class="hello_rig">
       <img class="xiaolu" src="${ctx}/common/images/titlelu1.png"> 
       </li>
      <ul>
     </div>

 

以下是js

(function(){
    var hh = document.getElementById("overTime");
    var now = new Date();
    var hours =now.getHours();
    if(hours>=12){
     hh.innerHTML = "HI,下午好";
    }else{
     hh.innerHTML ="HI,上午好";


    } 
})()

 

 

 

总是报错Uncaught TypeError: Cannot set property 'innerHTML' of null

 

祁祁的主页 祁祁 | 菜鸟二级 | 园豆:215
提问于:2016-03-24 19:44
< >
分享
最佳答案
0

if(hh!=null)

if(hours>=12){
     hh.innerHTML = "HI,下午好";
    }else{
     hh.innerHTML ="HI,上午好";
    }

}试试呢

收获园豆:10
手持鱼篓 | 菜鸟二级 |园豆:214 | 2016-03-24 19:49

谢谢。真的不报错了呢,这是为什么呀????

祁祁 | 园豆:215 (菜鸟二级) | 2016-03-29 15:16
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册