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

时间:2013-05-02 06:26:35

标签: javascript jquery dialog

如何将警告框更改为jquery对话框?

脚本编码的一部分:

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

2 个答案:

答案 0 :(得分:3)

您应该使用 confirm 命令

window.confirm("are you sure");

如果你想使用jquery中的对话框,你应该查看ui扩展名。取自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>
  

这是默认对话框,可用于显示信息。可以使用“x”图标移动,调整大小和关闭对话框窗口。

答案 1 :(得分:1)

我们可以使用确认

result = confirm(“确认单击确定”);

查看所有选项http://www.w3schools.com/js/js_popup.asp

使用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>