为什么当按钮被禁用时我无法创建警报。但是当按钮启用时我可以收到警报吗?
$(document).on('click', '#printpage', function() {
alert('clicked');
if ($("#printpage").is(":disabled")) {
alert("Disabled");
} else {
alert("enabled");
}
});
最佳答案
禁用按钮不可点击。
如果您想要警报,请使用 class
而不是 disabled
属性,并使用 css 对其进行样式化。
$(document).on('click', '#printpage', function() {
if ($("#printpage").is(".disabled")) {
alert("Disabled");
} else {
alert("enabled");
}
});
.disabled {
cursor: not-allowed;
opacity: .5;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button class="disabled" id="printpage">Print</button>
关于javascript - 当按钮被禁用时创建警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56079720/