【问题标题】:jQuery replace the css style with specified class namejQuery用指定的类名替换css样式
【发布时间】:2020-08-31 01:33:18
【问题描述】:

我有一个带有 html 内容的字符串 var,请检查以下内容

var dc = "<html><head><style type='text/css' >.round {border:2px solid grey;width:auto;}</style></head> <body></body>";

现在我该如何更改.round 范围内的内容。我的意思是border:2px solid grey;width:auto; ??

我可以使用replaceWith 或任何其他技术吗??

请回复,谢谢。

【问题讨论】:

    标签: jquery string replacewith


    【解决方案1】:

    replaceWith 将是您最好的选择,和/或使用正则表达式来帮助抓住“{”和“}”之间的那个位。

    归根结底,您所拥有的只是一个字符串,因此只需要对字符串进行操作即可。

    【讨论】:

    • 你能帮我做这件事吗?
    【解决方案2】:

    是的,确实,要替换大括号内的字符串,您可以使用以下内容:

    dc=dc.replace(/\{([^}]+)\}/, "your new string");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-02
      • 2017-03-13
      • 2011-01-23
      • 2018-09-14
      • 2012-03-04
      • 1970-01-01
      相关资源
      最近更新 更多