如果你可以使用jquery,請嘗試下面的代碼,這可以讓你有可能根據你的要求做代碼工作。在JavaScript
函數定義:
<script>
function ConfirmMessage(title, message) {
$('#confirmboxpopup').fadeIn(500, function() {
$('#confirmbox').animate({ 'top': '100px' }, 50);
});
$('#confirmboxtitle').html(title);
$('#confirmboxmessage').html(message);
$('#confirmbox').show(50);
$('#confirmboxok').attr('onclick', okFunction());
$('#confirmboxcancel').attr('onclick', onCancelClickFunction());
}
function okFunction()
{
'enter code here to implement next step if user agree'
}
function onCancelClickFunction()
{
'enter code here to fadeout for id #confirmboxpopup to remove popup.'
}
</script>
定義標籤HTML id爲:
<div id="confirmboxpopup" class="confirmboxpopup" style="display: none"></div>
<div id="confirmbox" class="confirm_message">
<div id="confirmboxtitle" class="title"></div>
<div id="confirmboxmessage" class="message"></div>
<div id="confirmbuttons" style="float: right; padding-top: 7px">
<button id="confirmboxok" type="button">ok</button>
<button id="confirmboxcancel" type="button">cancel</button>
</div>
</div>
調用函數: 你只需要調用ConfirmMessage與一些參數,如「ConfirmMessage(標題,消息) 」。
無論如何,我只會使用jQuery-UI對話框或其他選項。遠離內置的確認/警告框。您將以這種方式獲得更多功能。 – 2012-03-12 16:49:40