如何在页面加载时自动打开jquery ui对话框?

时间:2022-12-01 16:17:12

I need my dialog to open when the page is loaded automatically. What is the way to do it using jquery. Without any user interaction to open it.

当页面自动加载时,我需要打开对话框。使用jquery做什么的方法是什么。没有任何用户交互来打开它。

I tried this code but it dint work

我试过这个代码,但是它很有效

<html>
    <head>
        <link rel="stylesheet" type="text/css" href="css/style.css" media="screen,projection" />
        <script type="text/javascript" src="script/jquery-1.4.2.min.js"></script>
        <link type="text/css" href="css/jquery-ui-1.8.1.custom.css" rel="stylesheet" />
        <script type="text/javascript" src="script/jquery-ui-1.8.1.custom.min.js"></script>
        <script type="text/javaScript">
            $(function(){
                $('#dialog').dialog({
                    autoOpen: true,
                    width: 600,
                    buttons: {
                        "Ok": function() {
                            $(this).dialog("close");
                        }
                    }
                });
            });
        </script>
    </head>
    <%
                if (session.getAttribute("user") == null) {
                    response.sendRedirect("index.jsp");
                }
    %>
    <body>
        <div id="wrap">
            <div id="header">
            </div>

            <div id="leftside">
                <h2 class="hide">Sample menu:</h2>
                <ul class="avmenu">
                    <li><a href="dashboard.jsp" class="current">Dash Board</a></li>
                    <li><a href="createpoll.jsp">Create Poll</a></li>
                    <li><a href="availpoll.jsp">Vote Poll</a></li>
                    <li><a href="viewresults.jsp">View Results</a></li>
                    <li><a href="underconstruction.jsp">Settings</a></li>
                    <li><a href="logout">Log Out</a></li>
                </ul>
            </div>

            <div id="contentwide">
                <%@page import="com.jSurvey.entity.question" %>
                <%@page import="com.jSurvey.controller.questionJpaController" %>
                <%
                  //code to write data to database
                %>
                <div id="dialog"><p>Data Added successfully</p></div>
            </div>
            <div id="footer">
            </div>
        </div>
    </body>
</html>

Please help.

请帮忙。

2 个解决方案

#1


4  

use autoOpen: true, to make it open directly when page loads

使用autoOpen:true,使页面加载时直接打开

#2


0  

Try:

尝试:

  $(document).ready(function() {
      // Your dialog code here
  });

EDIT: The only other thing you could try is a $(body).load(function(){//your dialog here}); if that doesn't do anything, then there's some other underlying issue with the way your page is loading.

编辑:你可以尝试的唯一的另一件事是$(body).load(function(){//你的对话在这里});如果这没有做任何事情,那么页面加载的方式还存在一些其他潜在问题。

#1


4  

use autoOpen: true, to make it open directly when page loads

使用autoOpen:true,使页面加载时直接打开

#2


0  

Try:

尝试:

  $(document).ready(function() {
      // Your dialog code here
  });

EDIT: The only other thing you could try is a $(body).load(function(){//your dialog here}); if that doesn't do anything, then there's some other underlying issue with the way your page is loading.

编辑:你可以尝试的唯一的另一件事是$(body).load(function(){//你的对话在这里});如果这没有做任何事情,那么页面加载的方式还存在一些其他潜在问题。