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条)

报告相同问题?

悬赏问题

  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助
  • ¥15 STM32控制MAX7219问题求解答