gpt4 book ai didi

javascript - removeAttr() 未应用?

转载 作者:行者123 更新时间:2023-11-30 07:17:05 32 4
gpt4 key购买 nike

我正在为我当前的项目使用 zepto.js,它具有与 jquery 相同的 removeAttr() 方法。

我正在将 margin-top 应用于一堆元素 – 工作正常。

var $apply = $('aside[role="sub"], aside[role="event-info"], aside[role="attend"]');
$apply.css('margin-top', '100px'); //works fine

但是我还需要在调整大小事件中再次删除它。

if ( $(window).width() <= 984 ) {
//$apply.removeAttr('style'); //doesn't take effect
$apply.css('margin-top', '0'); //works fine
console.log('< 984');
}

所以我可以将 margin-top 设置回 0 但不能从选择器中完全删除样式属性。

有什么想法吗?我没有收到任何错误,它只是没有生效。

最佳答案

删除它的正确方法是在使用 .css 时不设置值。

$apply.css('margin-top', ''); // remove property

When a value for a property is empty, that property is removed.

阅读更多 here .

关于javascript - removeAttr() 未应用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11671363/

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