可能的重复项:
Javascript 确认弹出窗口"是,否"按钮而不是"确定"和"取消"
请有人帮我制作一个带有"是"和"否"按钮的确认框,而无需使用 jquery 或 VB.Script。我已经搜索了很多,但我用jquery得到了所有的答案,但这不是我的要求。
我必须从确认框函数调用另一个函数。我在下面使用的代码
.HTML
<a href="#" onlick="show_confirm('<?php echo $cat_id; ?>')">Delete</a>
和Javascript
<script type="text/javascript">
function show_confirm(cat_id)
{
var conf = confirm("Are you sure you want to delete the file");
if (conf ==true)
{
deleteCatagory(cat_id);
}
}
function deleteCatagory(cat_id)
{
var obj = document.getElementById("file_"+cat_id);
callAjax(cat_id,obj);
}
</script>
非常简单。您必须自定义具有"是"和"否"按钮的 HTML 框。"是"按钮执行代码并隐藏框,"否"按钮仅隐藏框。像这样简单的事情就可以了:
.HTML
<div id="confirmation">
Are you sure you want to delete the category?<br>
<input type="button" onclick="deleteCategory(document.getElementById('catID').value);this.parentNode.style.display='none';" value="Yes">
<input type="button" onclick="this.parentNode.style.display='none';" value="No">
<input type="hidden" id="catID" value="0">
</div>
.CSS
<style type="text/css">
<!--
#confirmation {
display: none;
position: absolute;
top: 50%;
left: 50%;
background-color: white;
border: 2px solid white;
padding: 3px;
text-align: center;
width: 200px;
height: 50px;
}
</style>
更新show_confirm()
:
function show_confirm(catID) {
document.getElementById('catID').value=catID;
document.getElementById('confirmation').style.display='block';
}
你需要自己创建它,这个: http://dev.sencha.com/deploy/ext-4.0.0/examples/message-box/msg-box.html 似乎有办法做到这一点,但这是从 5 分钟的谷歌搜索开始的。 其他人建议使用div 来做到这一点,这是我个人的偏好。
如果您对确认框为您提供的"确定"或"取消"选项感到满意,则只需修复通话中的拼写错误即可。我会这样做
<a href="JavaScript:void(0);" onclick="show_confirm('<?php echo $cat_id; ?>');">Delete</a>
但是,如果您想更改默认文本,那么您就不走运了默认confirm
弹出窗口。你必须想出一个基于html的"弹出窗口"。