【问题标题】:The title bar is still on screen after the jQuery dialogbox closedjQuery 对话框关闭后标题栏仍在屏幕上
【发布时间】:2015-12-16 21:33:43
【问题描述】:

我使用 jQuery 对话框加载另一个网页。关闭对话框后出现问题。对话框关闭后,标题栏仍在屏幕上。我希望它完全消失。对话框在 div 上加载并成功打开。有人会告诉我如何解决这个问题。提前致谢。

对话框关闭后的屏幕截图。

有我的父页面代码:

 <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Test1.aspx.vb"      Inherits="Test.Test1" %>

 <!DOCTYPE html>

   <html xmlns="http://www.w3.org/1999/xhtml">
   <head runat="server">
  <script src="include/dialog.js" type="text/javascript"></script>
  <link rel="stylesheet" href="/include/jquery-ui-themes-1.11.4/themes/smoothness/jquery-ui.css" />
  <script  language="javascript" src="/include/jquery-2.1.4.min.js" type="text/javascript"></script>
  <script language="javascript" src="/include/jquery-ui-1.11.4/jquery-ui.js" type="text/javascript"></script>
    <script language="javascript" src="/include/dailog1.js" type="text/javascript"></script>


  <script type="text/javascript" language="javascript">
    $(document).ready(function () {
        $('#btnOrder').click(function (e) {
             e.preventDefault();
             openBox('Test2.aspx?orderid=0', 'Testing', 700, 650);

        });
    });

</script>
<title>Parent page</title>
 </head>
<body>
   <form id="form1" runat="server">
    <div>
    <asp:Button ID="btnOrder" runat="server" Text="Order" />
     <div id="dialog-box"/>
   </div>
  </form>
  </body>
</html>

有子页面代码:

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Test2.aspx.vb" Inherits="Test.Test2" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
  <head runat="server">
    <script type="text/javascript" language="javascript" src="Include/scripts.js"></script>
    <script language="javascript" src="/include/dailog1.js" type="text/javascript"></script>
     <script type="text/javascript" language="javascript" src="Include/jquery-2.1.4.min.js"></script>
    <link rel="stylesheet" href="/include/jquery-ui-themes-1.11.4/themes/smoothness/jquery-ui.css" />
      <script language="javascript" src="/include/jquery-2.1.4.min.js" type="text/javascript"></script>
      <script language="javascript" src="/include/jquery-ui-1.11.4/jquery-ui.js" type="text/javascript"></script>

   <base target="_self" />
   <script language="javascript" type="text/javascript">
 $(document).ready(function () {
        $('#btnCancel').click(function (e) {
            e.preventDefault();
            CloseDialogBox();

        });
 });
     </script>
  <title>Dialog Box</title>
</head>
<body>
    <form id="form1" runat="server">
      <div>
         <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
         <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="* Required" ControlToValidate="TextBox1"></asp:RequiredFieldValidator>
        <asp:Button ID="btnCancel" runat="server" Text="Cancel" />
        <asp:Button ID="Button2" runat="server" Text="Save" />
     </div>
   </form>
</body>
</html>

有我的代码打开对话框:

function openDailogBox(url, name, width, height) {  
    $('#dialog-box').load(url).dialog({
        autoOpen: false,
        resizable: true,
        height: height
        width: width,       
        title: name,
        modal: true,
       draggable: false

    });
  $('#dialog-box').dialog('open');
  return false;
 }

关闭按钮位于对话框内的网页上:

  $(document).ready(function () {
        $('#btnCancel').click(function (e) {
            e.preventDefault();
            CloseDialogBox();

        });
    });

这是关闭对话框的代码。 (如果我不包含附加对话框的代码,我会收到 JavaScript 运行时错误:在初始化之前无法调用对话框上的方法;试图调用方法“关闭”)

function CloseDialogBox() {   

    $('#dialog-box').dialog({
    autoOpen: false,
    resizable: true,     
    title: name,
    modal: true,
});

$('#dialog-box').dialog('close');   

}

【问题讨论】:

    标签: jquery jquery-ui


    【解决方案1】:

    我发现,如果我在 Test2.aspx 上注释下面的 jQuery 文件,它就会起作用。

     <script type="text/javascript" language="javascript" src="Include/jquery-2.1.4.min.js"></script>
         <link rel="stylesheet" href="/include/jquery-ui-themes-1.11.4/themes/smoothness/jquery-ui.css" />
            <script language="javascript" src="/include/jquery-2.1.4.min.js" type="text/javascript"></script>
            <script language="javascript" src="/include/jquery-ui-1.11.4/jquery-ui.js" type="text/javascript"></script>
    

    【讨论】:

      【解决方案2】:

      您可以在尝试使用之前测试对话框小部件是否已附加到元素。

      function CloseDialogBox() {
          if ($"#dialog-box").is(":ui-dialog")) {
              $("#dialog-box").dialog("close");
          }
      }
      

      【讨论】:

      • 感谢您的回答,但没有奏效。单击按钮时,RequiredFieldValidator 在页面上显示警告并且它没有运行该功能。
      • 你能做一个演示问题的sqlfiddle吗?
      • @Bamar,我想你希望我在 jsFiddle 上制作我的项目。我从来没有使用过它。我想我需要创建一个帐户。我需要显示另一个页面。我该怎么做?
      • 您无需创建帐户即可使用 jsfiddle。您也可以使用Stack Snippets 在此处制作示例
      • 抱歉,我尝试在 Stack Snippets 上添加我的代码,但它没有运行。我不知道该怎么做
      猜你喜欢
      • 2015-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多