简体   繁体   English

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

[英]Trouble trying to overriding !important style

My goal is to make the fields for filling out an ecommerce checkout address appear after the user starts typing the zip code.我的目标是在用户开始输入 zip 代码后显示填写电子商务结帐地址的字段。

For that, I wrote this JS code below为此,我在下面编写了这段 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>   

And this is the CSS I need to overwrite这是我需要覆盖的 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;
}

I'm getting this error on the console我在控制台上收到此错误

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

Thank you in advance for your help!预先感谢您的帮助!

Perhaps try removing the 'element' from each of the 'setProperty' statements.也许尝试从每个“setProperty”语句中删除“元素”。 ie: document.getElementById('billing_state_field').style.setProperty("display", "block", "important");即: document.getElementById('billing_state_field').style.setProperty("display", "block", "important");

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

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