我相信这是一个非常简单的解决方案。我制作了这个javacript函数,用于测试div上是否存在某种CSS样式,然后绕另一个div移动。但是,它不起作用,我不知道为什么。有人可以告诉我为什么这个JavaScript函数不执行?
的JavaScript:
function sale() {
var style = document.getElementsByClassName("product-single__price--wrapper").getAttribute("style");
if (style !="display: none;") {
document.getElementByClassName("product-single__description").style.marginTop = "70px !important";
}
}
window.onload = sale;
*“有人可以告诉我为什么这个JavaScript函数不执行吗?”*你似乎没有在任何地方调用函数?但即使你做了'document.getElementById(“ProductPrice”)。style.margin-top = ...'是一个错误。如果包含“-',则无法使用点符号访问属性。 –
因为没有'style.margin-top'这样的东西,除非你想从'style.margin'中减去一个名为'top'的变量。我想你想'.style.marginTop'。 –
这个函数在任何时候都不检查CSS样式吗?如果不是我怎么能这样做呢? @FelixKling –