繁体   English   中英

尝试覆盖 !important 样式时遇到问题

[英]Trouble trying to overriding !important style

我的目标是在用户开始输入 zip 代码后显示填写电子商务结帐地址的字段。

为此,我在下面编写了这段 JS 代码

<script>


window.onload = function(){
    document.getElementById('billing_postcode').onclick = function(){
    //console.log('Hello world');
   
document.getElementById('billing_address_1_field').element.style.setProperty("display", "block", "important");

document.getElementById('billing_address_2_field').element.style.setProperty("display", "block", "important");

document.getElementById('billing_billing_number_field').element.style.setProperty("display", "block", "important");

document.getElementById('billing_city_field').element.style.setProperty("display", "block", "important");

document.getElementById('billing_state_field').element.style.setProperty("display", "block", "important");
  }
}



</script>   

这是我需要覆盖的 CSS


#billing_address_1_field {
    display: none !important;
}

#billing_address_2_field{
    display: none !important;
}

#billing_billing_number_field{
    display: none !important;
}

#billing_city_field{
    display: none !important;
}

#billing_state_field{
    display: none !important;
}

我在控制台上收到此错误

Uncaught TypeError: Cannot read property 'style' of undefined
    at HTMLInputElement.document.getElementById.onclick ((index):384)
document.getElementById.onclick @ (index):384

预先感谢您的帮助!

也许尝试从每个“setProperty”语句中删除“元素”。 即: document.getElementById('billing_state_field').style.setProperty("display", "block", "important");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM