2009-08-05 68 views
0

我一直在努力让模态窗口在新的网站上工作一段时间。我第一次尝试jqmodal,并没有显示模式的问题,但关闭按钮从未工作 - 或者至少他们在一些页面上工作,但不在其他页面上工作。我花了大量的精力去调试,并且找不到问题。jquery modal windows - 用greybox和jqmodal关闭挫折

我最近尝试了greybox,看看我是否有更好的运气,但遇到了一个非常类似的问题。右上角的关闭按钮可以正常工作,但我无法在作为关闭模式的模式中制作按钮。我试过了:

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

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

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

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

我觉得我错过了一些非常基础的东西,因为我一直遇到类似的问题。顺便说一句,该网站是用jQuery写在ASP.NET MVC中的,我现在主要是在Firefox上进行测试。

我也意识到这个问题有点含糊,所以我很欣赏任何想法,如果需要可以提供更多信息。提前致谢!

编辑:我仍然不知道如何继续。 Nick的想法很好,但是我看到Firebug或Venkman页面上没有Javascript错误。据我所知,窗户应该关闭。

为什么上面的第二个'onclick'事件工作,但不是第二个?

回答

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()是。所以这让我思考。

是您点击Like按钮:

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

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

萤火虫让我发现,parent.parent是窗口,所以把后:

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

在页面上我现在得到一个警告显示。

+0

谢谢,尼克。我了解它是如何工作的,并在某些情况下有效。我试图找出为什么一个页面上的模式按预期关闭,但另一页上的模式拒绝这样做。 – user101306 2009-08-05 16:04:37

+0

大部分时间我都遇到过这样的问题,它是由一些无关的JavaScript错误引起的。 你有没有可以发布/托管的例子? – 2009-08-05 16:13:55

+0

现在不行。我的JavaScript调试技巧非常渺茫,所以如果你能建议一个特定的地方看看或调试的方式可能会有帮助。谢谢! – user101306 2009-08-05 16:18:09

0

而不是使用谷歌给页面的URL要重定向

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

是代码关闭和重定向按钮点击jQuery的灰箱。