使用按钮单击打开的 jQuery UI 模式未加载网页
jQuery ui modal opened with button click is not loading the webpage
我需要在模态对话框中显示网页。此弹出窗口应仅在单击按钮后出现,其中按钮具有 url 路径。我想出了以下代码,但它显示一个空白的模态窗口。你能建议我在这里可能错过什么吗?谢谢。
<!doctype html>
<html lang="en">
<head> <meta charset="utf-8">
<title>jQuery UI Dialog - Default functionality</title>
<link rel="stylesheet" href="jquery-ui.css">
<script src="jquery-1.10.2.js"></script>
<script src="jquery-ui.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://code.jquery.com/ui/1.11.3/jquery-ui.min.js"></script>
<link rel="stylesheet" href="style.css">
<script type="text/javascript">
$(function() {
$('#clickMe').click(function(event) {
var link = this;
$('<div>').dialog({
modal: true,
open: function ()
{
$(this).load($(link).attr("href"));
},
height: 400,
width: 400,
title: 'This is popup window',
show: 'puff',
hide: 'puff'
});
});
});
</script>
</head>
<body>
<button id="clickMe" href="http://www.google.com/">Google</button>
</body>
</html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://code.jquery.com/ui/1.11.3/jquery-ui.min.js"></script>
<script type="text/javascript">
$(function() {
$('#clickMe').click(function(event) {
var link = this;
$('<div>').dialog({
modal: true,
open: function() {
console.log('link', link);
console.log('link.href should be undefined', link.href);
console.log('$(link).attr("href") should get you the value', $(link).attr("href"));
$(this).load($(link).attr("href"));
},
height: 400,
width: 400,
title: 'This is popup window'
});
});
});
</script>
<button id="clickMe" href="http://www.google.com/">Google</button>
<button id="clickMe2" href="http://www.yahoo.com/">Yahoo</button>
问题 1:两个按钮上的id
相同,id
在整个 HTML 文档中必须是唯一的。
问题 2:您需要使用 $(link).attr("href")
访问 href
的值(请参阅随附的代码段)。
与Google,Yahoo演示),您将获得CORS(跨源请求错误)。如果在实际应用程序中从同一域加载页面,则应该可以工作。
相关文章:
- AngularJS ui路由器html5模式中断路由
- 在编辑内联模式下禁用Kendo Ui网格按钮
- jQuery UI模式对话框覆盖淡出
- angular ui bootstrap:当模式关闭时,promise被解析/拒绝
- 可以'不要通过背景点击来取消自定义UI引导模式
- 具有 UI 引导模式窗口的父$scope子
- 在单击 UI 网格上的链接时引导模式
- 如何将参数传递到 UI 路由器状态的模式窗口
- 如何在高级编译模式下使用 Google Closure 编译器编译 jQuery UI 小部件
- 延迟角度 UI 模式关闭
- 角度 UI 模式开机自检
- Jquery UI don'使用bootstrap 3模式时效果不佳
- 为什么我的UI应用程序嵌套在引导模式中时无法工作
- 如何在不创建数组的情况下使用NgFor来生成矩阵UI模式
- Angular-UI引导日期选择器未在引导模式上显示
- jquery ui模式框中的表单隐藏后,键盘将不再被调用
- 语义 UI 模式未定义
- 显示 ui 路由器模式而不刷新父状态
- 将 UI 模式对话框添加到新的 DIV 标记
- jQuery UI 模式对话框在关闭之前挂起