2
如何在簡單的javascript確認對話框中顯示yes而不是OK。我沒有更多的JavaScript知識,那麼最簡單的方法是什麼?我嘗試了一些代碼,但沒有得到結果。在確認對話框中顯示是/否而非確定
function doConfirm("Are you sure?", yesFn, noFn) {
var confirmBox = $("#confirmBox");
confirmBox.find(".message").text(msg);
confirmBox.find(".yes,.no").unbind().click(function() {
confirmBox.hide();
confirmBox.prev().remove();
});
confirmBox.find(".yes").click(yesFn);
confirmBox.find(".no").click(noFn);
confirmBox.show();
var overlay = $("<div>").css({
position: "fixed",
top: 0,
left: 0,
right: 0,
bottom: 0,
backgroundColor: "rgba(255,255,255,0.5)"
}).insertBefore(confirmBox);
}
$(function() {
$("form").submit(function (e) {
e.preventDefault();
var form = this;
doConfirm("Are you sure?", function yes() {
form.submit();
}, function no() {
return false;
});
});
});
body { font-family: sans-serif; }
#confirmBox
{
display: none;
background-color: #eee;
border-radius: 5px;
border: 1px solid #aaa;
position: fixed;
width: 300px;
left: 50%;
margin-left: -150px;
padding: 6px 8px 8px;
box-sizing: border-box;
text-align: center;
}
#confirmBox .button {
background-color: #ccc;
display: inline-block;
border-radius: 3px;
border: 1px solid #aaa;
padding: 2px;
text-align: center;
width: 80px;
cursor: pointer;
}
#confirmBox .button:hover
{
background-color: #ddd;
}
#confirmBox .message
{
text-align: left;
margin-bottom: 8px;
}
<form method="post" action="">
<input type="hidden" name="html" value="<p>Your data has been deleted</p>" />
<input type="submit" value="Delete My Data" />
</form>
<div id="confirmBox">
<div class="message"></div>
<span class="button yes">Yes</span>
<span class="button no">No</span>
</div>
也試過這個http://jsfiddle.net/Xtreu/269/
http://jsfiddle.net/Xtreu/270/但我仍然不明白這一點。需要幫忙!
'函數doConfirm( 「你確定嗎?」,yesFn,noFn)'應該是'功能doConfirm(味精,yesFn,noFn)' – Barmar
你的意見,使用http://t4t5.github.io/ sweetalert / –