Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我是否可以在纯javascript中创建自定义确认框(不使用jquery),其工作方式与window.confirm相同?_Javascript - Fatal编程技术网

我是否可以在纯javascript中创建自定义确认框(不使用jquery),其工作方式与window.confirm相同?

我是否可以在纯javascript中创建自定义确认框(不使用jquery),其工作方式与window.confirm相同?,javascript,Javascript,在confirm.js中有类似于此页面的代码 我想在php中做一些操作,比如从数据库中删除记录,比如点击yes按钮后提交表单,点击no按钮后返回false 这可能吗 <script type="text/javascript" src="confirm.js"></script> <script type="text/javascript"> function validation() { if(document.getElementById('tbo

在confirm.js中有类似于此页面的代码

我想在php中做一些操作,比如从数据库中删除记录,比如点击yes按钮后提交表单,点击no按钮后返回false

这可能吗

<script type="text/javascript" src="confirm.js"></script>
<script type="text/javascript">
function validation()
{
    if(document.getElementById('tbox').value=='')
    {
        alert('enter value');
        return false;
    }
    else
    {
        confirm.render('','','sub_btn');
    }
}
</script>
<form method="get">
    <table width="100%" height="500px" z-index="500000" style="background:yellow;">
        <tr>
            <td>
                <input type="text" id="tbox">
            </td>
        </tr>
        <tr>
            <td>
                <input type="submit" id="sub_btn" value="Submit" onclick="return validation()">
            </td>
        </tr>
    </table>
</form>
没有

无法在DOM中创建阻止JavaScript事件循环的对话

您必须停止显示时正在执行的任何操作,然后让对话框中的选项重新启动您停止的流程。

无法在DOM中创建阻止JavaScript事件循环的对话

您必须停止显示时正在执行的任何操作,然后让对话框中的选项重新启动您停止的流程。

否您无法准确复制默认的确认/警报/提示提示。 这些代码会阻止javascript运行超过该行,直到返回某些内容,这是javascript无法做到的

有很多自定义模式对话框,为了避免无法阻止javascript等待响应,它们使用回调。 您将一个函数传递给对话框窗口的调用,该函数将在对话框窗口完成后执行

以下是一些例子:

一个快速的谷歌会给你更多。 以前我自己做了一个完全来自javascript的,因为我不想有css文件。它的功能远不如其他浏览器,但它是纯javascript,因此这里有一个链接:

不,您无法准确复制默认的确认/警报/提示提示。 这些代码会阻止javascript运行超过该行,直到返回某些内容,这是javascript无法做到的

有很多自定义模式对话框,为了避免无法阻止javascript等待响应,它们使用回调。 您将一个函数传递给对话框窗口的调用,该函数将在对话框窗口完成后执行

以下是一些例子:

一个快速的谷歌会给你更多。 以前我自己做了一个完全来自javascript的,因为我不想有css文件。它的功能远不如其他浏览器,但它是纯javascript,因此这里有一个链接:

嗨,我的以下评论已被删除。现在我已经找到了一个解决方案,我将在下面的评论中向大家介绍:

我已经用纯javascript创建了一个自定义确认框代码,它看起来和工作起来都很棒。这太容易了。但问题是,如果我必须在同一网页上从用户处获得两个确认,那么我必须为每个具有不同函数名称的函数集编写单独的函数集2

我不知道回调如何帮助我解决问题。回调函数也会立即执行,无需等待检查用户是否单击了确认或取消按钮

我是否可以将回调函数名传递给另一个使用setTimeOut并等待(比如15分钟)用户单击确认或取消的函数?点击按钮,我可以将用户的选择记录在一个全局变量和clearTimeOut中,以立即执行下一部分。15分钟后,如果没有收到用户响应,则将其视为响应取消,这应该是安全的。有人想尝试解决这个问题吗

我不接触或阅读jQuery、Angular等。请不要让我参与这些讨论

好的,这是解决办法。主文件是customConfirm.htm:-

<html>
<head>
<style>
/* ~~~~~~~~~~~~~~~ Style for the pop box with blackener ~~~~~~~~~~~~~~~~~~~ */
.popBoxStyle { position: absolute; text-align: center;

visibility:hidden;
z-index: 2000;                                                              /* Nairit: Set high so that shows over page contents */
cursor: default;

background-color: #FFFFFF;
border:2px solid;
border-color: #6F7072;
border-radius:6px;                              /* More gives rounder edges */
box-shadow: 10px 10px 5px #606060;              /* Shadow can be used when black overlay is not used on the rest of the page. Or black has low opacity */

filter:alpha(opacity=100);                                          /* Works in IE */
opacity:1.0;                                                        /* Works in others. This is for the opacity of the box's background */

padding:3px;
}

.liner { clear:both; height:1px; background-color:#cccccc; }
.spacer { clear:both; height:5px; }

.black { position:absolute; z-index:1999; }

button.close { float:right; margin:5px; cursor:pointer; background-color:#d9534f !important; border-radius:4px !important; color:#fff !important; font-size:21px; font-weight:bold; line-height:1; color:#000000; }
/* ~~~~~~~~~~~~~ Style for the pop box with blackener ends ~~~~~~~~~~~~~~~~~~ */
</style>

<script language="javascript" src="PopBox.js"></script>
<script language="javascript">
var affirm = false; tm_ref=null, cb_func_name=null;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function customConfirm(func,msg)
{
initializePopBox();

popBox.innerHTML = "<table width='100%' cellspacing='0' cellpadding='5' border='0'>" +
"<tr><td>CONFIRM</td>" +
    "<td><button type='button' class='close' style='float:right;margin:5px;' onClick='setUserResponse(false);'>x</button></td></tr>" +
"<tr><td colspan='2'><div class='liner'></div></td></tr>" +
"<tr><td colspan='2'>"+msg+"</td></tr>" +
"<tr align='right'>" +
    "<td><input type='button' name='b_cancel' value='Cancel' onClick='setUserResponse(false);'></td>" +
    "<td><input type='button' name='b_confirm' value='Confirm' onClick='setUserResponse(true);'></td></tr>" +
"</table>";

aWidth = 300; aHeight = 150;
finalizePopBox(50);
cb_func_name = func;                        // Storing the callback function's name globally
tm_ref = setTimeout(func, 30000);           // 60000 milli seconds = 1 minute. 600000 milli seconds = 10 minutes. 900000 milli seconds = 15 minutes
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function handleConfirmResponse()
{
hidePop();
    if( affirm )
    {
    alert("He said Yes");       // Do your work here
    }

    else
    {
    alert("He said No");        // Do nothing
    }
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function setUserResponse(respo)
{
affirm = respo;
clearTimeout(tm_ref);
cb_func_name();                 // Gets the function name from global and calls it
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
</script>
</head>

<body>
<div id="blackener" class="black"></div>
<div id="popContainer" class="popBoxStyle"></div>                   <!-- NK: The pop-up appears in this div -->

<input type="button" name="b1" value="Delete" onClick="customConfirm(handleConfirmResponse,'Are you sure?');">

</body>
</html>

我在同一网页的两个不同位置成功地呼叫了customConfirm。我必须传递两个不同的响应处理程序回调函数名。在调用customConfirm之前,我必须对每个回调函数中需要其值的任何变量进行全局设置。但这是值得努力的-

您好,我的以下评论已被删除。现在我已经找到了一个解决方案,我将在下面的评论中向大家介绍:

我已经用纯javascript创建了一个自定义确认框代码,它看起来和工作起来都很棒。这太容易了。但问题是,如果我必须在同一网页上从用户处获得两个确认,那么我必须为每个具有不同函数名称的函数集编写单独的函数集2

我不知道回调如何帮助我解决问题。回调函数也会立即执行,无需等待检查用户是否单击了确认或取消按钮

我是否可以将回调函数名传递给另一个使用setTimeOut并等待(比如15分钟)用户单击确认或取消的函数?点击按钮,我可以将用户的选择记录在一个全局变量和clearTimeOut中,以立即执行下一部分。15分钟后,如果没有收到用户响应,则将其视为响应取消,这应该是安全的。有人想尝试解决这个问题吗 他的

我不接触或阅读jQuery、Angular等。请不要让我参与这些讨论

好的,这是解决办法。主文件是customConfirm.htm:-

<html>
<head>
<style>
/* ~~~~~~~~~~~~~~~ Style for the pop box with blackener ~~~~~~~~~~~~~~~~~~~ */
.popBoxStyle { position: absolute; text-align: center;

visibility:hidden;
z-index: 2000;                                                              /* Nairit: Set high so that shows over page contents */
cursor: default;

background-color: #FFFFFF;
border:2px solid;
border-color: #6F7072;
border-radius:6px;                              /* More gives rounder edges */
box-shadow: 10px 10px 5px #606060;              /* Shadow can be used when black overlay is not used on the rest of the page. Or black has low opacity */

filter:alpha(opacity=100);                                          /* Works in IE */
opacity:1.0;                                                        /* Works in others. This is for the opacity of the box's background */

padding:3px;
}

.liner { clear:both; height:1px; background-color:#cccccc; }
.spacer { clear:both; height:5px; }

.black { position:absolute; z-index:1999; }

button.close { float:right; margin:5px; cursor:pointer; background-color:#d9534f !important; border-radius:4px !important; color:#fff !important; font-size:21px; font-weight:bold; line-height:1; color:#000000; }
/* ~~~~~~~~~~~~~ Style for the pop box with blackener ends ~~~~~~~~~~~~~~~~~~ */
</style>

<script language="javascript" src="PopBox.js"></script>
<script language="javascript">
var affirm = false; tm_ref=null, cb_func_name=null;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function customConfirm(func,msg)
{
initializePopBox();

popBox.innerHTML = "<table width='100%' cellspacing='0' cellpadding='5' border='0'>" +
"<tr><td>CONFIRM</td>" +
    "<td><button type='button' class='close' style='float:right;margin:5px;' onClick='setUserResponse(false);'>x</button></td></tr>" +
"<tr><td colspan='2'><div class='liner'></div></td></tr>" +
"<tr><td colspan='2'>"+msg+"</td></tr>" +
"<tr align='right'>" +
    "<td><input type='button' name='b_cancel' value='Cancel' onClick='setUserResponse(false);'></td>" +
    "<td><input type='button' name='b_confirm' value='Confirm' onClick='setUserResponse(true);'></td></tr>" +
"</table>";

aWidth = 300; aHeight = 150;
finalizePopBox(50);
cb_func_name = func;                        // Storing the callback function's name globally
tm_ref = setTimeout(func, 30000);           // 60000 milli seconds = 1 minute. 600000 milli seconds = 10 minutes. 900000 milli seconds = 15 minutes
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function handleConfirmResponse()
{
hidePop();
    if( affirm )
    {
    alert("He said Yes");       // Do your work here
    }

    else
    {
    alert("He said No");        // Do nothing
    }
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function setUserResponse(respo)
{
affirm = respo;
clearTimeout(tm_ref);
cb_func_name();                 // Gets the function name from global and calls it
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
</script>
</head>

<body>
<div id="blackener" class="black"></div>
<div id="popContainer" class="popBoxStyle"></div>                   <!-- NK: The pop-up appears in this div -->

<input type="button" name="b1" value="Delete" onClick="customConfirm(handleConfirmResponse,'Are you sure?');">

</body>
</html>

我在同一网页的两个不同位置成功地呼叫了customConfirm。我必须传递两个不同的响应处理程序回调函数名。在调用customConfirm之前,我必须对每个回调函数中需要其值的任何变量进行全局设置。但这是值得努力的-

但是我不知道怎么做你说的我不明白但是我不知道怎么做你说的我不明白我可以用纯javascript创建自定义确认框而不使用jquery:是的。与window一样工作。确认?:否。这是我今天能很快找到的最好的选项。我可以用纯javascript创建自定义确认框,而不使用jquery:Yes。和window一样工作。确认?:不。这是我今天能很快找到的最好的选择。我已经看到了所有提到的例子仍然不能做我想做的事情。我已经看到了所有提到的例子仍然不能做我想做的事情