如何在第二次加载页面时禁用Jquery Ui对话框

时间:2012-04-14 13:54:50

标签: jquery-ui dialog

我已经在我的母版页上创建了一个jquery ui对话框,所以在我的网站对话框出现在所有页面中,我使用clickevent关闭对话框,之后我再次进入下一页对话框open.once我关闭对话框它应该在下一页上没有打开。请给我一些想法。 我怎么能这样做?

这是我的jquery代码:

 <script type="text/javascript">

  $(document).ready(function () {

  $("#dialog").dialog({ modal: false, resizable: false,
 bgiframe: true, draggable: false, position: ['right', 'bottom'], height: 150,     width:     300
 });


 $("#<%=btnCancel.ClientID%>").click(
  function () {
    $("#dialog").dialog('close');
 return false;
  });
   $("#<%=btnyes.ClientID%>").click(
  function () {
 var url = ".....";
  $(location).attr('href', url);
 return false
    });

      });
  </script>

这是我的设计代码:

  <div id="dialog" title="How Are We Doing?" style="width:500px; margin:0 0;"  background-color="white">

    <asp:Label ID="Label1" runat="server" Text="Please take a minute to give us your feedback…MICROMO.com’s User Feedback Program."></asp:Label>
    <asp:Button ID="btnyes" runat="server" Text="YES" BackColor="#0099cc" width="40px" ForeColor="White" Font-Bold="true" />
    <asp:Button ID="btnCancel" runat="server" Text="NO" width="40px" BackColor="#0099cc" ForeColor="White" Font-Bold="true"/>

     </div> 

1 个答案:

答案 0 :(得分:0)

我们可以使用JS Cookie函数来设置条件,以便在Document.ready函数之前显示对话框。 下面我给出了功能代码:

<script type="text/javascript">          
$(document).ready(function ()  
{
var check=getCookie("clicked");alert(check);
if (check!='true' && check!="")
{    

$("#dialog").dialog({ modal: false, resizable: false,
bgiframe: true, draggable: true, position: ['right', 'bottom'], height: 150,     
width:     300

});

}

$("#<%=btnCancel.ClientID%>").click(

function () {
$("#dialog").dialog('close');
$("#dialog").dialog('disable');
return false;
});
$("#<%=btnyes.ClientID%>").click(
function () {
var url = "http://www.w3schools.com/jquery/jquery_intro.asp";
$(location).attr('href', url);  
setCookie("clicked",true,2);    
return false
});
});
</script>

Cookie Js文件

function setCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}
function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
x=x.replace(/^\s+|\s+$/g,"");
if (x==c_name)
{
return unescape(y);
}
}
}
相关问题