gpt4 book ai didi

javascript - 使用 jQuery 或任何其他方法删除样式

转载 作者:行者123 更新时间:2023-11-29 22:18:49 25 4
gpt4 key购买 nike

我真的需要你的专家帮助!

我正在制作一个展示 HTML 电子邮件的网站。因此,我需要从特定的 div 中删除所有样式,以便我可以从电子邮件中复制和粘贴 HTML。这将保持电子邮件的原始设计。

我已经设置了一个测试页面 here并尝试使用 jQuery 中的 removeAttr,但它似乎不起作用。

我很擅长编写 HTML 和 CSS,但 javaScript 对我来说是新手,所以任何真正清晰的例子都会很棒。

顺便说一下,我对 jQuery 并不着迷。任何能完成这项工作的东西都会很棒!

在此先感谢大家,

布兰登。

这是 JavaSript 和 HTML

<link rel='stylesheet' id='style-css'  href='css/style.css' type='text/css' media='all' />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script>

</head>

<body>
<script type='text/javascript'>
$(document).ready(function() {
$('h1').removeAttr('style');
});
</script>
<p>This is a paragraph tag.</p>
<h1>This is a H1 tag.</h1>
<div>
<p>This is a p tag inside a styled div.</p>
<table width="200" border="1">
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
<tr>
<td>7</td>
<td>8</td>
<td>9</td>
</tr>
</table>
</div>
</body>
</html>

这是CSS

table, th, td {
border: 1px solid #CCCCCC;
}
table {
margin-bottom: 1.5em;
max-width: 100%;
width: 100%;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
p, address {
margin-bottom: 1.5em;
font-size:19px;
}
h1{
border-bottom: 5px solid #666666;
}
h1{
font-family: "Oswald";
line-height: 1.5;
margin: 0 0 0;
padding-bottom: 0.3em;
text-transform: lowercase;
}
h1{
font-size: 2em;
line-height: 1;
margin-bottom: 1em;
}
h1, h2, h3, h4, h5, h6 {
clear: both;
font-size: 100%;
font-weight: normal;
}
div{
background-color:#9F0;
}

最佳答案

jQuery(function($) {
$("style, link[rel=stylesheet]").remove();
$("*").removeAttr("style");
});

关于javascript - 使用 jQuery 或任何其他方法删除样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13572750/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com