我正在嘗試制作一個在單擊 X 按鈕(close.png)時向上滑動的視窗。
我用 JavaScript 添加了 Wrap 元素,并在里面添加了一個 img 元素。
然后,我輸入了以下 JavaScript,但是當我按下 X 按鈕時沒有任何變化。
<script>
const parent3 = document.querySelector('#wrap');
const billingField3 = document.querySelector('#woocommerce-input-wrapper');
const newImg = document.createElement('img');
newImg.setAttribute("src", "//t1.daumcdn.net/postcode/resource/images/close.png");
newImg.setAttribute('id', 'btnFoldWrap');
newImg.style.cssText = 'cursor:pointer;position:absolute;right:0px;top:-1px;z-index:1';
newImg.onclick = "offDaumZipAddress();"
parent3.insertBefore(newImg, billingField3);
</script>
function offDaumZipAddress() {
jQuery("#wrap").slideUp();
}
網站結構是
<div class="woocommerce-billing-fields__field-wrapper">
<p class="billing_postcode_find_field">..
<span class="woocommerce-input-wrapper">...
</span>
</p>
<div id="wrap" ..>
<img src="..."></img>
</div>
<p class="billing_address_1_field">
<span class="woocommerce-input-wrapper">
使用 chrome 開發者工具的控制臺檢查不會顯示任何錯誤。
有人可以讓我知道我錯過了什么嗎?
謝謝你。
uj5u.com熱心網友回復:
屬性的值onclick必須是函式參考,而不是 JavaScript 字串。
newImg.onclick = offDaumZipAddress;
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/425066.html
標籤:javascript html jQuery
