繁体   English   中英

用按钮单击打开的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(跨源请求错误)。 如果在您的实际应用程序中从同一域加载页面,那应该可以工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM