简体   繁体   English

如何用对话框替换警报框?

[英]How can I replace an alert box with a dialog box?

How can I change the alert box into a jquery dialog box? 如何将警报框更改为jquery对话框?

Part of the script coding: 脚本编码部分:

  if(answeredAnsData.length==8){
            for(var x=0;x<8;x++){
                $('#text'+(x)).attr('disabled','disabled');
            }
         window.alert("test"); //alert box here
        }
    });

You should use the confirm command 您应该使用确认命令

window.confirm("are you sure");

if you want to use the dialog box from jquery you should look into the ui extension. 如果要使用jquery中的对话框,则应查看ui扩展。 Example taken from http://jqueryui.com/dialog/ 示例取自http://jqueryui.com/dialog/

<!doctype html>

<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>jQuery UI Dialog - Default functionality</title>
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" />
    <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
    <script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>
    <link rel="stylesheet" href="/resources/demos/style.css" />
    <script>
        $(function() {
            $( "#dialog" ).dialog();
        });
    </script>
</head>
<body>

This is the default dialog which is useful for displaying information. 这是默认对话框,可用于显示信息。 The dialog window can be moved, resized and closed with the 'x' icon. 对话框窗口可以使用“ x”图标移动,调整大小和关闭。

We can use confirm 我们可以使用确认

result = confirm("To confirm click OK"); 结果=确认(“确认单击确定”);

To see all options http://www.w3schools.com/js/js_popup.asp 要查看所有选项, 请访问http://www.w3schools.com/js/js_popup.asp

To use jquery dialog 使用jQuery对话框

<html lang="en">
<head>
<meta charset="utf-8" />
<title>jQuery UI Dialog - Default functionality</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<script>
$(function() {
$( "#dialog" ).dialog();
});
</script>
</head>
<body>
<div id="dialog" title="Basic dialog">
<p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
</div>
</body>
</html>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM