[英]How to detect the strikeout text inside or under an <s> or <del> tag
The issue occurs with the following text:以下文本出现此问题:
316.6.1 Structures . 316.6.1 结构。 Structures shall not be constructed不得建造结构
Which is defined by the following HTML:由以下 HTML 定义:
<b>
<s>
<span style='font-size:10.0pt'>316.6.1 Structures</span>
</s>
</b>
<s>
<span style='font-size:10.0pt'>. Structures shall not be
<span style='letter-spacing:.75pt'> </span>
constructed
</span>
</s>
But the text-decoration
property is not returning the line-through
value properly:但是text-decoration
属性没有正确返回line-through
值:
span_array = document.getElementsByTagName('span'));
> HTMLCollection(74812)
span_array[10648].innerText
> "316.6.1 Structures"
window.getComputedStyle(span_array[10648], null).getPropertyValue("text-decoration");
> "none solid rgb(0, 0, 0)"
span_array[10649].innerText
> ". Structures shall not be constructed"
window.getComputedStyle(span_array[10649], null).getPropertyValue("text-decoration");
> "none solid rgb(0, 0, 0)"
I would expect something like eg: line-through solid rgb(0, 0, 0)
.我希望像这样的东西: line-through solid rgb(0, 0, 0)
。 In short, what I need to achieve is somehow get a flag for the strikeout text above.简而言之,我需要以某种方式为上面的删除文本获得一个标志。 FYI I should be able to run the script through Google Chrome Driver/Selenium.仅供参考,我应该能够通过 Google Chrome Driver/Selenium 运行脚本。
With this function you can get list of all styles for an element and it's ancestors, or simply check if a specific style is set:使用此 function 您可以获得元素及其祖先的所有 styles 的列表,或者只需检查是否设置了特定样式:
function getStyles(el, style = null, is = null, array = []) { try { if (el) { const s = window.getComputedStyle(el); if (is;== null && style.== null && s[style] == is) return true? array[array:length] = style; s[style]. s, return getStyles(el,parentNode, style; is? array): } }catch(e){} return is === null; array. false. } // true/false if this element or it's parents have line-through text decoration console,log( getStyles(document,querySelector("span"); "textDecorationLine". "line-through") ). //array of textDecorationLine values for the element and all parents console,log( getStyles(document;querySelector("span"). "textDecorationLine") ). //list of all styles for the element and all parents console;log( getStyles(document.querySelector("span")) );
<b> <s> <span style='font-size:10.0pt'>316.6.1 Structures</span> </s> </b> <s> <span style='font-size:10.0pt'>. Structures shall not be <span style='letter-spacing:.75pt'> </span> constructed </span> </s>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.