【问题标题】:Get all the content within <style> tag in a html file using jquery使用 jquery 获取 html 文件中 <style> 标记内的所有内容
【发布时间】:2017-06-07 10:46:31
【问题描述】:

我有一个 html 文件和一些在 style 标签内写的 css。我需要提取此标签内的文本。例如:

<style>
    html,body {
        margin: 0px;
        width:100%;
    }
    .center-text {
        text-align: center;
    }
</style>

我需要使用 jquery 在字符串中提取此标记内的值。我尝试了几个帖子,但无法得到任何合适的答案。

【问题讨论】:

  • 我也试过stackoverflow.com/questions/8189252/…,但它对我不起作用。我正在检查更新的 chrome 版本。
  • 这是个奇怪的要求。目的是什么?
  • @YoYo 我需要将此 css 存储在数据库中。

标签: javascript jquery html css


【解决方案1】:

你试过了吗?

$("#YourDiv").html($("style").html())

这将获取 css 代码作为字符串并将其放入 div 如果您需要将其保存到 db,您可以通过 ajax 将其发送到您的服务器

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-11
    • 2017-02-07
    • 2021-11-14
    • 2014-11-10
    • 2012-02-07
    相关资源
    最近更新 更多