lim*_*ilo 5 html javascript php wordpress woocommerce
我在WooCommerce单一产品页面上使用模式显示给用户显示其他信息,这些信息仅在产品详细信息页面上可见。它也可以工作,但是下面的脚本无处不在,因此我得到了错误消息:
未捕获的TypeError:无法将属性'onclick'设置为null
当某人单击产品详细信息页面之外的某处时。是否可以仅在产品详细信息页面上加载脚本?
我的HTML:
<button id="myBtn" class="help-link">Brauchen Sie Hilfe?</button>
<div id="myModal" class="modal">
<div class="modal-content">
<span class="close"><i class="nm-font nm-font-close2"></i></span>
<h4>Brauchen Sie Hilfe?</h4>
<p>Sollten Sie Fragen zu Produkten haben, oder Hilfe bei der Konfiguration benötigen, steht unser Kundenservice Ihnen gerne zur Verfügung.</p>
<p>Erreichbar von Montag bis Freitag<br>10:00 - 18:00 <br>Tel.:040/655 646 91</p>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
脚本:
// Modal
var modal = document.getElementById('myModal');
// Get the button that opens the modal
var btn = document.getElementById("myBtn");
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// When the user clicks the button, open the modal
btn.onclick = function() {
modal.style.display = "block";
}
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
Run Code Online (Sandbox Code Playgroud)
要限制单个产品页面中的某些内容,只能is_product()在IF如下语句中使用:
<?php if ( is_product() ) { ?>
// your script goes here
<?php } ?>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
183 次 |
| 最近记录: |