jquery模态窗口 - 用greybox和jqmodal结束挫折

时间:2009-08-05 15:44:03

标签: asp.net-mvc modal-dialog

我一直在努力让模态窗口在新网站上运行一段时间。我首先尝试了jqmodal并且没有显示模态的问题,但是关闭按钮从未起作用 - 或者至少它们在某些页面上工作但在其他页面上没有。我在调试方面投入了大量精力,无法找到问题。

我最近试过greybox看看我是否运气好,但遇到了一个非常相似的问题。右上角的关闭按钮工作正常,但我无法在模态中创建一个按钮作为关闭。我试过了:

onclick="parent.parent.GB_hide();"

和类似的变体,但它们只是加载模态中设置的任何href。但是,如果我这样做:

onclick="top.window.location.href='www.google.com'; parent.parent.GB_hide();"

这将关闭模式并按预期打开Goog​​le。我无法弄清楚的是为什么我不能制作一个只是简单地关闭它的按钮。

我觉得自己错过了一些非常重要的东西,因为我一直遇到类似的问题。顺便说一句,该站点是用ASP.NET编写的,带有jquery,我现在主要在Firefox上进行测试。

我也意识到这个问题有点模糊,所以我很感激任何想法,如果要求可以提供更多信息。提前谢谢!

编辑:我仍然不知道如何继续。尼克的想法很好,但我在Firebug或Venkman页面上看不到任何Javascript错误。据我所知,窗口应该关闭。

为什么第二个'onclick'事件会起作用,而不是第二个?

2 个答案:

答案 0 :(得分:3)

如果我正确地阅读了您的问题,您只是在关闭模态对话框时遇到问题。

我只是使用jqModal汇总了一个例子:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="Scripts/jquery-1.3.2.js" type="text/javascript"></script>
<script src="Scripts/tmp/jqModal.js" type="text/javascript"></script>
<style type="text/css">
    .jqmWindow
    {
        display: none;
        position: fixed;
        top: 17%;
        left: 50%;
        margin-left: -300px;
        width: 600px;
        background-color: #EEE;
        color: #333;
        border: 1px solid black;
        padding: 12px;
    }
    .jqmOverlay
    {
        background-color: #000;
    }
 .jqmWindow
    {
        position: absolute;

    }
</style>
<script type="text/javascript">
    $().ready(function() {
        $('#dialog').jqm();

        $('#jqmOpen').click(function() {
            $('#dialog').jqmShow();
            return false;
        });
    });
</script>
</head>
<body>
<a href="#" id="jqmOpen" name="jqmOpen">Open</a>
<div class="jqmWindow" id="dialog">
    <a href="#" class="jqmClose">Close</a>
    <input type="button" class="jqmClose" value="Close" id="jqmCloseBtn" name="jqmCloseBtn" />
    Some text in the modal dialog
   </div>
</body>
</html>

我已经将超链接和按钮都放在了例如。似乎jqModal需要/查找类来附加关闭触发器。

修改

我刚刚尝试了上面的确切代码并且我没有收到JavaScript错误但也没有发生任何事情,这是预期的,因为我的代码不知道GB_hide()是什么。所以这让我思考。

点击按钮是否为:

<input type="button" value="Close" id="Button1" name="Button1" onclick="parent.parent.GB_hide();" />

如果是这样,什么是parent.parent.GB_hide()? GB_hide()可能是您未在此页面上实现的功能。

Firebug告诉我,parent.parent是Window,所以放完后:

<script type="text/javascript">
    function GB_hide() {
        alert('Close');
    }
</script>
页面上的

我现在收到一条警告。

答案 1 :(得分:0)

而不是使用谷歌给你想要重定向的页面网址

 OnClientClick="top.window.location.href='http://localhost/yourpagename.aspx'; parent.parent.GB_hide();" 

是在按钮点击时关闭和重定向jquery灰色框的代码。