Jquery - 使 UI 对话框出现在 href 上

标签 jquery jquery-ui-dialog

所以我这里有这个:

这是一个非常简单的 UI 对话框,它会倒计时,直到我的用户被重定向。如果他们在框外单击,则会被取消。

我是否可以创建这个,以便通过点击 URL 来完成?

我还想传递一个参数(用户将被重定向到的网址)

<!DOCTYPE html>
<html>
<head>

  <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
  <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>



  <script type="text/javascript">
    function setClosed(){
      isClosed=true;
    }
    function alertBlah() {   
       if (!isClosed)
   $(location).attr('href',"http://www.google.com").delay(3000);
}

   //Wait for the document to load
   $(document).ready(function() {
      isClosed=false;

  //Create the dialog and open it
  $("#dialog").dialog();
  $("p.5").fadeOut(0).delay(500).fadeIn(400);
  $("font.4").fadeOut(0).delay(1000).fadeIn(400);
  $("font.3").fadeOut(0).delay(1500).fadeIn(400);
  $("font.2").fadeOut(0).delay(2000).fadeIn(400);
  $("font.1").fadeOut(0).delay(2500).fadeIn(400);
  $("h2.by").fadeOut(0).delay(3000).fadeIn(400);

  setTimeout(alertBlah,3500);

  //Bind to the ui-widget-overlay and watch for when it is clicked
  $('.ui-widget-overlay').live("click", function() {
     //Close the dialog
     $("#dialog").dialog("close");
     setClosed();

  }); 


  });

 </script>
 </head>

 <body style="font-size:62.5%;">




   <div class="ui-widget-overlay" >
      <a href="#" class="close">Leave My Site</a>

      <div id="dialog" class="flora" title="Leaving my site" ><center>Leaving in...
         <font class="5">5..</font>
         <font class="4">4..</font>
         <font class="3">3..</font>
         <font class="2">2..</font>
         <font class="1">1..</font>

  </br>
  <h2 class="by">Good By!</h2>
  </center>
</div>

最佳答案

假设你有一个 anchor :

<a href="#" class="close">Leave My Site</a>

你可以这样做:

$('a.close').click(function(e){
    //$(this) would be your anchor
    //awesome magic here
    e.preventDefault();
});

e.preventDefault 是重要的部分,因为它可以防止 anchor 默认操作发生。

关于Jquery - 使 UI 对话框出现在 href 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6118915/

相关文章:

javascript - 如何使用 e.preventDefault(); 禁用、启用然后再次禁用 ipad/iphone 中的滚动?

jquery - 如何让多个JQuery弹出,点击超链接?

javascript - 如何在单击按钮时显示自定义对话框

jqueryui对话框定位

javascript - jquery 每个循环的随机元素 id

javascript - 将数据添加到 html 表格单元格时如何更改 col-span

javascript - 在jquery中动态获取输入值

javascript - JQuery:切换新创建的 DIV -> 链接到 $(this) 而不是 $(this).closest()

jquery - 未捕获的 TypeError : $(…). 不是一个函数

JQUERY UI 对话框表单在关闭事件时丢失按钮操作