摘要: 我想通过javascript获取HTML样式标签的属性的最终值。我已经为网页编写了CSS样式表。我更改了变量属性的值。我想在javascript中读取此值。我得到的是html中显示的值,而不是我通过css更改为的值。
问题: 当我希望它返回覆盖的400px值时,此javascript从html返回200px。
saveEdit.style.getPropertyValue('-editor-height');
详细信息: 我的html
“(1)200px”。原始的html。
<div class="editor ql-container"
data-action="editor"
aria-label="Content editor"
style="--editor-height:200px; --editor-height-small-viewport:200px;">
“ css修改”指向我的CSS代码。我正在使用手写笔注入代码。
“覆盖”显示级联的结果。
我的CSS文件摘录
/* This gives a larger editor window. [ Apple size is 200px ] */
.ql-container {
--editor-height:400px !important;;
}
这可以使编辑窗口显示为400px。
这是我的JavaScript,它读取--editor-height的值。我正在使用滑脂注入代码。
var saveEdit = document.querySelector('div.editor.ql-container');
if (debug>=2) console.log ("saveEdit is ",saveEdit);
if (saveEdit) {
let allStyle = saveEdit.getAttribute("style")
if (debug>=2) {
console.log("style is ",saveEdit.getAttribute("style"));
console.log("allStyle is ", allStyle)
console.log("saveEdit.attributes are ",saveEdit.attributes);
}
editorHeight=saveEdit.style.getPropertyValue('--editor-height');
console.log("editorHeight is ",editorHeight)
这是我在控制台上看到的这段代码的内容。
saveEdit is <div class="editor ql-container"
data-action="editor"
aria-label="Content editor"
style="--editor-height:200px; --editor-height-small-viewport:200px;">
hu.user.js:364:18
style is --editor-height:200px; --editor-height-small-viewport:200px;
hu.user.js:368:8
allStyle is --editor-height:200px; --editor-height-small-viewport:200px;
hu.user.js:369:8
saveEdit.attributes are NamedNodeMap [ class="editor ql-container",
data-action="editor",
aria-label="Content editor",
style="--editor-height:200px; --editor-height-small-viewport:200px;" ]
hu.user.js:373:8
editorHeight is 200px
实际网页:https://discussions.apple.com/thread/250147075 您需要有一个帐户。点击回复。 我正在使用Waterfox 56.2.7运行macOS优胜美地。 Greasemonkey 3.17 触控笔1.5.2