我試圖向用戶顯示一個警告模式,以說明該按鈕不可點擊。由于pointer-events: none上課,我使用的按鈕不可點擊disable。
即使按鈕不可點擊,我也想在用戶點擊該按鈕時顯示警告。
如何獲得點擊動作并顯示警告?任何人都可以幫忙嗎?
.disable {
pointer-events: none
}
<button type="button" class="btn disable">Button</button>
uj5u.com熱心網友回復:
您可以使用包裝器并在其上系結點擊事件。
document.querySelector('div').onclick = alert.bind(null, 'hey')
.disable {
pointer-events: none
}
<div><button type="button" class="btn disable">Button</button></div>
uj5u.com熱心網友回復:
顯然使用與指標事件不同的方式
const but = document.getElementById("but")
but.addEventListener("mousedown",function(e) {
e.preventDefault()
this.textContent = "Nope!"
})
but.addEventListener("mouseup",function(e) {
e.preventDefault()
this.textContent = "Button"
})
.disable {
background-color: light-grey;
opacity:.5
}
<button type="button" id="but" class="btn disable">Button</button>
jQuery
$("#but")
.on("mousedown", function(e) {
e.preventDefault()
this.textContent = "Nope!"
})
.on("mouseup", function(e) {
e.preventDefault()
this.textContent = "Button"
})
.disable {
background-color: light-grey;
opacity: .5
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button type="button" id="but" class="btn disable">Button</button>
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/364145.html
標籤:javascript 查询 css
上一篇:如何獲取帶有顏色串列的下拉串列?
