删除内联样式

此功能还保留隐藏的内容。

function remove_style(all) {
  var i = all.length;
  var j, is_hidden;

  // Presentational attributes.
  var attr = [
    'align',
    'background',
    'bgcolor',
    'border',
    'cellpadding',
    'cellspacing',
    'color',
    'face',
    'height',
    'hspace',
    'marginheight',
    'marginwidth',
    'noshade',
    'nowrap',
    'valign',
    'vspace',
    'width',
    'vlink',
    'alink',
    'text',
    'link',
    'frame',
    'frameborder',
    'clear',
    'scrolling',
    'style'
  ];

  var attr_len = attr.length;

  while (i--) {
    is_hidden = (all[i].style.display === 'none');

    j = attr_len;

    while (j--) {
      all[i].removeAttribute(attr[j]);
    }

    // Re-hide display:none elements,
    // so they can be toggled via JS.
    if (is_hidden) {
      all[i].style.display = 'none';
      is_hidden = false;
    }
  }
}
用法

像这样调用函数:

var all = document.getElementsByTagName('*');
remove_style(all);

注意:通过通配符查询选择页面中的所有元素可能很慢,具体取决于页面中有多少个元素。 您可以使用较小的元素集来提高性能:

var set = document.getElementById('foo').getElementsByTagName('bar');
remove_style(set);

内森·史密斯(Nathan Smith)编写的代码。

翻译自: https://css-tricks.com/snippets/javascript/remove-inline-styles/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要为`this.$confirm`添加CSS样式,您可以使用以下两种方法之一: 方法一:使用`customClass`属性 您可以在`this.$confirm`的配置对象中使用`customClass`属性来添加自定义类名,然后在CSS样式表中定义相应的样式。 示例代码: ```javascript this.$confirm('是否立即删除该类型邮件?删除后不会影响用户已经收到的邮件,删除的模版数据无法找回。', '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning', customClass: 'my-confirm-style' }); ``` 在CSS样式表中定义类名为`my-confirm-style`的样式: ```css .my-confirm-style { /* 添加您的自定义样式 */ background-color: #f0f0f0; color: #333; } ``` 方法二:使用内联样式 您可以直接在`this.$confirm`的配置对象中使用`showCancelButton`和`showConfirmButton`属性来添加内联样式。 示例代码: ```javascript this.$confirm('是否立即删除该类型邮件?删除后不会影响用户已经收到的邮件,删除的模版数据无法找回。', '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning', showCancelButton: true, showConfirmButton: true, cancelButtonStyle: 'background-color: #f0f0f0; color: #333', confirmButtonStyle: 'background-color: #f0f0f0; color: #333' }); ``` 在上述代码中,您可以通过设置`cancelButtonStyle`和`confirmButtonStyle`属性来添加内联样式。 请根据您的需求选择适合您的方法,并根据自己的样式需求进行相应的定义。希望这可以帮助到您!如果还有其他问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值