2009-05-26 46 views
0

我有一个非常奇怪的问题!我在我的一个页面中使用了blockUI JQuery插件,它工作正常。我为另一个页面做了同样的事情,当$ unblockUI被调用时,它并没有解锁页面。JQuery BlockUI不解除页面

下面是代码:

function showCommentBox() 
{  

    $("#commentBox").addClass("modalPopup"); 

    alert($("#commentBox").hasClass("modalPopup")); 

    $.blockUI({ message: $("#commentBox") });  
} 

function cancelComment() 
{  
    alert($("#commentBox").hasClass("modalPopup")); 

    $.unblockUI(); 
} 

当$( “#commentBox”)hasClass( “modalPopup”)中,而该cancelComment功能评估不工作返回 “假” 的页面。工作正常的页面返回true。

回答

2

@Azam -上面发布的代码没有任何问题。没有理由不应该这样做。我直接在帖子中复制了代码,并在此jsbin page中进行了测试。亲自查看。

为了尽可能简单,这是我用于HTML主体的所有内容。

<input type="button" value="Show Comment" onclick="showCommentBox()" /> 
    <div id="commentBox" style="display:none"><br/> 
    This is the text from the CommentBox Div<br/> 
    <input type="button" value="Cancel" onclick="cancelComment()" /> 
    </div> 

编辑:读你的一些其他职位后,我意识到了问题的真正原因是,你要添加一个GridView的ItemTemplate里面的“commentBox”分区。这会导致创建具有相同ID的同一个div乘以gridview中的行数。通常,在多个HTML元素中使用相同的id是不好的,但这是gridview所做的。

这是我测试过的一种解决方法,它可以工作。改变你的两个函数来此:

function showCommentBox() { 
    $.currentBox = $("#commentBox"); 
    $.currentBox.addClass("modalPopup"); 
    alert($.currentBox.hasClass("modalPopup")); 
    $.blockUI({ message: $.currentBox });  
} 

function cancelComment() {  
    alert($.currentBox.hasClass("modalPopup")); 
    $.unblockUI(); 
} 

这里我使用jQuery的变量来存储到commentBox DIV参考,并传递一个以$ .blockUI,以这种方式调用$ .unblockUI()会正常工作。

+0

请阅读我编辑的答案,并让我知道它是否可以帮助你 – 2009-06-04 23:06:56