【问题标题】:how to get <head> content of the current page with jquery or JS如何使用 jquery 或 JS 获取当前页面的 <head> 内容
【发布时间】:2011-04-05 06:47:10
【问题描述】:

如何获取&lt;head&gt;当前页面的内容

【问题讨论】:

    标签: javascript jquery head


    【解决方案1】:

    您可以像这样使用 javascript DOM API:

    var headContent = document.getElementsByTagName('head')[0].innerHTML;
    

    【讨论】:

    • 只需使用document.head.innerHTMLCan I use?
    • @AlexandruEftimie 而document.head 可能是大多数现代浏览器的首选。它不适用于 Internet Explorer 8 或更早版本
    【解决方案2】:

    您可以使用element selector 获取&lt;head&gt;,例如:

    $("head")
    //for example:
    alert($("head").html()); //alerts the <head> children
    

    You can give it a try here

    【讨论】:

      【解决方案3】:

      简单来说:

      document.head

      // 返回对象 DOM 对象

      document.head.innerHTML

      // 返回文本,例如:'

      页面标题...'

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-11
      • 2022-08-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-03
      • 1970-01-01
      相关资源
      最近更新 更多