dqhr76378 2018-01-17 07:19
浏览 97
已采纳

如果更改页面,请更改标记<h1>

I have some JavaScript code, and if the homepage or index (e.g. at malaspulang.com) the tag <h1> does not change. But if I change the page (e.g. at malaspulang.com/lifestyle), the tag <h1> will be replaced with <h2>.

This my code:

<div id="header" class="hide"><h1>this my title</h1></div>
<script>
if(window.URL === 'malaspulang.com'){

}else{

 $('#header').empty();
 $('#header').html('<h2>this my title</h2>');
}
</script>

In my homepage site, the tag <h1> should replace with <h2> I think that my code is true, but I am so confused with this code. So if anyone can help me, I will be happy :)

NB: If anyone that's code with PHP, you can tell me :)

  • 写回答

7条回答 默认 最新

  • duanlei2458 2018-01-24 04:57
    关注

    Maybe like this :

    <div class="hide" id="header">
      <h1>this my title</h1>
    </div>
    <script>
       $(document).ready(function(){
          console.log(document.URL);//this optional , just display your link at now
          var uri= document.URL;
          if(uri == 'http://malaspulang.com/'){ //use full link from your site
          //do nothing , because logical true
          }else{
              $('#header').empty();
              $('#header').html('<h2>this my title</h2>');
          }
       });
    </script>
    

    hope this help you

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(6条)

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?