久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      javascript怎么更改網(wǎng)頁標(biāo)題

      方法:1、使用“document.getElementsByTagName("title")[0].innerText = '值'”;2、使用“document.title='值'”;3、使用“$('title').html('值')”。

      javascript怎么更改網(wǎng)頁標(biāo)題

      本教程操作環(huán)境:windows7系統(tǒng)、javascript1.8.5版、Dell G3電腦。

      title在html中屬于特殊的節(jié)點(diǎn)元素,因?yàn)樗梢允褂?code>document.getElementsByTagName("title")[0]來獲取網(wǎng)頁的title標(biāo)簽,但卻無法用document.getElementsByTagName("title")[0].innerHtml用更改它的值。經(jīng)測試原生js有兩種方式可以修改,jQuery中也能簡單設(shè)置。下面給大家介紹一下。

      innerText 方式

      通過console.log(document.getElementsByTagName("title")[0]),發(fā)現(xiàn)能打印出<title>標(biāo)簽,標(biāo)簽里面只有文字節(jié)點(diǎn),故猜測只能識別TextNode,所以用innerText方式設(shè)置title的值,果然成功了。

      document.getElementsByTagName("title")[0].innerText = '需要設(shè)置的值';

      document.title方式

      經(jīng)過測試,還可通過document.title 設(shè)置title的值。

      console.log(document.title);      # 可以獲取title的值。 document.title = '需要設(shè)置的值';    # 設(shè)置title的值。

      例子

      window.onfocus = function () {  document.title = '恢復(fù)正常了...'; }; window.onblur = function () {  document.title = '快回來~頁面崩潰了'; };

      我們在瀏覽器取得了焦點(diǎn)和失去焦點(diǎn)的時(shí)候改變title的值,可以發(fā)現(xiàn)切換瀏覽器選項(xiàng)卡的時(shí)候,title發(fā)生了改變。

      jQuery方式

      當(dāng)然如果你的項(xiàng)目里面依賴jQuery,可以使用jq的方法設(shè)置

      $('title').html('值')  $('title').text('值')

      jq中兩種方式都可以實(shí)現(xiàn)

      總結(jié)

      原生js中我們可以通過 innerText , document.title 兩種方式動(dòng)態(tài)修改網(wǎng)頁的title .

      jq中我們可以通過 $('title').html('值') 或者 $('title').text('值') 進(jìn)行修改。

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號