我正在开发一个可嵌入的 javascript,它将 HTML 元素插入未知页面。我无法控制要插入 HTML 的页面的样式表。问题是我插入的 HTML 会被页面错误地风格化,我想防止这种情况发生。
确保我插入的元素是最不冗长和/或资源密集的exactly正如我希望的那样?有没有一种简单的方法可以清除给定 HTML 元素和子元素的所有样式?例如,在 Firebug 中,您可以删除所有样式。我感觉就像在那里must,并且至少should,是一种使某些 HTML 元素免受样式表规则约束的本机方法吗?
Example:
var myHTML = $("<div>my html in here</div>");
myHTML.resetAllStyles(); //<--- what would this function do?
myHTML.appendTo("body");
我真的想避免明确声明我插入的每个元素想要的属性......
PS:我在 JS 和 CSS 方面有丰富的经验,所以你可以假设我会理解你要告诉我的大部分内容。
我将把这个作为一种可能性扔掉。为您的小书签定制标签怎么样?由于 IE,需要对自定义 xml 命名空间进行更多修改,但可能对您有用。
jQuery 似乎也不介意。
http://jsfiddle.net/uvfAf/1/ http://jsfiddle.net/uvfAf/1/
jQuery:
$('#tester').animate({opacity: .3},1000);
HTML:
// Not the main HTML tags. These are embedded in the body as the root
// of the bookmarklet. Scary? Perhaps.
<html xmlns:customtag>
<style>
@media all {
customtag\:someElement {
width:100px;
height: 100px;
background: blue;
display: block;
}
customtag\:someOtherElement {
width: 50px;
height: 50px;
background: red;
display: block;
}
}
</style>
<customtag:someElement id='tester'>test</customtag:someElement>
<customtag:someOtherElement>test</customtag:someOtherElement>
</html>
我使用此页面来了解如何在 IE 中执行自定义标签:
http://happyworm.com/blog/tag/custom-tags/ http://happyworm.com/blog/tag/custom-tags/
EDIT:
看起来 IE 想要xmlns
在 HTML 标签中定义,所以我将容器更改为<html>
。不确定总体影响,但似乎有效。
我更新了示例和 jsFiddle。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)