gpt4 book ai didi

javascript - getComputedStyle() 意外行为

转载 作者:行者123 更新时间:2023-11-29 21:34:55 24 4
gpt4 key购买 nike

<分区>

在下面的代码示例中,我希望在控制台日志中看到下划线。相反,我看到

如何从 #one .yo 中的 text-decoration 属性中提取 underline 值?

setTimeout(function() {
var $el = document.querySelectorAll('#one .yo')[0];
var css = getComputedStyle($el).cssText;

console.log("text-decoration is set to:");
console.log(/text\-decoration\: ([^\;]+)/g.exec(css)?.[1] + '!');
console.dir($el);
console.log(window.getComputedStyle($el));

var $el2 = document.querySelectorAll('#two .yo')[0];
$el2.style.cssText = css;
}, 750);
* {
margin: 0;
padding: 0;
}
#one {
color: blue;
text-decoration: underline;
}
<div id="one">
<div class="yo">what's up</div>
</div>

<div id="two">
<div class="yo">what's up</div>
</div>

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