有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

未使用Jquery调用javascript确认对话框

我需要在jsp中的确认框中进行一些定制,这在使用javascript时是不可能的,但经过一点研究发现Jquery将有助于实现这一需求

尝试了以下代码,但在执行按钮单击操作时,确认框未显示、混乱且无法理解问题

下面是我的代码:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js">
</script>
</head>
<body>

 <script type="text/javascript" >

 $(document).ready(function(){
     $("#docs").click(function(){
         ConfirmDialog();
     });

     });

    function ConfirmDialog(){
         $('<div></div>').appendTo('body')
                      .html('<div><h6>'+"Do you want to export or open the document"+'?</h6></div>')
                     .dialog({
                            modal: true, title: '', zIndex: 10000, autoOpen: true,
                            width: 'auto', resizable: false,
                            buttons: {
                                Export: function () {
                                                                   $(this).dialog("close");
                                    alert("your document is being saved");
                                },
                                Open: function () {
//                                  
                                    $(this).dialog("close");
                                    alert("your document will open in another window");
                                }
                            },
                            close: function (event, ui) {
                                $(this).remove();
                            }
                        });
        };




</script>

<button id="docs">xxx docs</button>


</body>
</html> 

共 (2) 个答案

  1. # 1 楼答案

    视评论而定。 确保您正在导入以下脚本

    <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
    
    <script src="http://code.jquery.com/ui/1.11.1/jquery-ui.min.js"></script>
    
    <link rel="stylesheet" href="https://code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css" />
    

    在调用ConfirmDialog之前,应该先调用它们

  2. # 2 楼答案

    您需要包括jQueryUI库

    <script src="http://code.jquery.com/ui/1.11.1/jquery-ui.min.js"></script>