jquery - 你如何在对话框中打开一个 URL JQUERY UI

标签 jquery html jquery-ui jquery-ui-dialog

一段时间以来,我一直在寻找一种简单的解决方案。我想要一个页面(例如 http://www.google.com )显示在 JQuery UI 对话框窗口中。计划是稍后动态添加 URL,以便我站点的所有链接都将显示在所述窗口中。

我尝试了以下方法,但是单击链接时对话框窗口是空的。

<!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>Test</title>


<meta charset="utf-8" />
  <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css" />
  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <script src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script>
  <script>
$(document).ready(function() {
    $('#openwindow').each(function() {
        var $link = $(this);
        var $dialog = $('<div></div>')
            .load($link.attr('href'))
            .dialog({
                autoOpen: false,
                title: $link.attr('title'),
                width: 500,
                height: 300
            });

        $link.click(function() {
            $dialog.dialog('open');

            return false;
        });
    });
});
  </script>

</head>
<body>
<a id="openwindow" href="http://www.google.com">Click me to test.</a>
</body>
</html>

我找到了几个例子,但没有一个真正起作用。非常感谢您的帮助。

提前致谢。

最佳答案

您不需要建议的iframe,但您应该阅读有关对话框的文档here .

相反,您需要加载 .open 属性上的内容 --

$( "#openwindow" ).dialog({
 open: function(event, ui) {
   $('#divInDialog').load('test.html', function() {
     alert('Load was performed.');
   });
  }
});

此外,您似乎将 .eachid 一起使用 - id 应该在页面中是唯一的。使用 class 代替。

关于jquery - 你如何在对话框中打开一个 URL JQUERY UI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15459107/

相关文章:

jquery - 如何使用jquery在gridview中获取选定的(单选按钮)行值(标签)

html - 通过 MySQL 和 JSP 的 MCQ Quiz Web 应用程序

html - Flexbox 代码适用于除 Safari 之外的所有浏览器。为什么?

javascript - 在我的案例中如何检测 div 冲突?

javascript - jquery 多个输入字段的总和(如果一个输入中有相同的类)

javascript - 设置与 jsTree 一起使用的分层数组

javascript - 当 # 已经添加到 url 时,如何使用 javascript 或 jquery 将焦点设置在 div 上?

jquery - 清除或重置地理完整控制

java - 临时编码的工作流程

javascript - ng-model 未使用 $setViewValue 进行更新(采用 jquery-ui 自动完成)