我有这个小小的愚蠢点,我必须用自动测试来覆盖它,它让我疯狂,我无法得到的值:在css元素之前,代码非常简单,因为测试也是,但我仍然需要一些帮助。这是我的代码。
.text-currency-positive::before {
content: "+ ";
}
<div class="amount">
<span class="text-currency text-currency-positive text-monospace text-nowrap">
::before
100,00 €
</span>
</div>
答案 0 :(得分:0)
好的,我们走了:
gwt {
gwtVersion = "2.8.2"
modules "com.test.Device"
maxHeapSize = "8G"
compiler {
compileReport = true
}
}
然后我们添加伪元素:
<h1 class="element">The value of my pseudo element is: </h1> // see the class
现在JS:
.element:before {
content: '+NEW';
}
这还不够,因为这会返回一个字符串......&#34; +&#34;。所以我们这样做:
var content = window.getComputedStyle(
document.querySelector('.element'), ':before' // target the classes pseude
).getPropertyValue('content'); // here we can get the computed styles/values
显示它:
var makeVar = content.replace(/"/g, ''); // replace the quotes with nothing
var firstLetter = makeVar.charAt(0); // here we get the value of first char after we have replaced the quotes
如果你不用正则表达式替换引号,你将得到&#34; +&#34;回来了,但也许这就是你想要的。
干杯,链接: