[英]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.