【问题标题】:how to open jquery ui dialog automatically when the page loads?页面加载时如何自动打开jquery ui对话框?
【发布时间】:2010-06-06 01:32:33
【问题描述】:

我需要在页面自动加载时打开我的对话框。使用 jquery 的方法是什么。无需任何用户交互即可打开它。

我试过这段代码,但它不起作用

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

请帮忙。

【问题讨论】:

标签: jquery jquery-ui dialog jquery-ui-dialog


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    试试:

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

    编辑: 您唯一可以尝试的另一件事是 $(body).load(function(){//your dialog here});如果这不起作用,则说明您的页面加载方式存在其他一些潜在问题。

    【讨论】:

    • $(function () { /* Your dialog code */ }) 等价于$(document).ready(function () { /* Your dialog code */ }
    • 是的,当我进一步研究时,我才意识到这一点。又一个盲人带领盲人的例子。 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-04
    相关资源
    最近更新 更多