3 回答

TA貢獻1847條經驗 獲得超11個贊
方式1:你可以使用這個:
<button name="remove" onclick="return confirm('Are you sure?')" style="margin-left: -15%; border-radius: 15px;" class="button button2">Remove</button>
這return是非常重要的
方式2:
function myFunction() {
if (confirm('Are you sure?')) {
//Do SomeThing...!
}
}

TA貢獻1880條經驗 獲得超4個贊
您需要驗證確認響應
function myFunction() {
if (confirm("Do you want to remove?!")) {
//do stufff here...
console.log('success')
} else {
console.log('cancel')
}
}
<button name="remove" onclick="myFunction()"class="button button2">Remove</button>

TA貢獻1829條經驗 獲得超6個贊
確保你做 preventDefault 因為你的刪除按鈕在表單內
document.getElementById("uniqueId").addEventListener("click", function(event){
event.preventDefault();
if(confirm("Msg")){
//do something
}
});
<form method="post">
<button name="remove" id="uniqueId" style=" border-radius: 15px;" class="button button2">Remove</button>
</form>
確保每個按鈕都有唯一的 id
- 3 回答
- 0 關注
- 100 瀏覽
添加回答
舉報