English 中文(简体)
如何移除 < style> 标签内的东西?
原标题:How to remove stuff inside <style> tags?

我试图为一个论坛制作此脚本, 它允许在文章中使用标签 。 不幸的是, 当我们写这些 CSS 样式时, 我们无法使用线断线, 因为窗体读作 < code@ lt; br> s, 并且它会破坏一切 。

他们看起来是这样的:

<style type="text/css"><!-- <br>#herp { background: #fff; }<br> --></style>

如果我们停止读取 s > 的窗体, 它会影响其它元素。 因此我们尝试用此方法删除这些元素 :

var style = document.getElementsByTagName("style"); for(x=1;x<style.length;x++) { style[x].innerHTML.replace(/<br>/gi,""); }

徒劳无益

坦率地说,我不知道这些样式标签之间有什么实体。 我不认为它们会重写字符串,也不会发表评论。 因此替换 () 似乎不起作用 。

有什么想法吗?

最佳回答
var style = document.getElementsByTagName("style");
for(x=1;x<style.length;x++) {
    style[x].innerHTML=style[x].innerHTML.replace(/<br>/gi,"");
}
问题回答

您可以使用 document. stype Sheets 获得样式表对象

在控制台尝试这个

for(i in document.styleSheets){
    if(!isNaN(i)){
         document.styleSheets[i].disabled = true;
    }
}




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签