创建一个带有参数的JQuery对话框模态函数


Create a JQuery dialog modal function with parameters

我在Jquery和java脚本方面有点新手,在这件事上有点困惑。这是我从JQuery UI中获取的一个简单的模态消息警报代码。

问题是该函数在HTML代码中的div类中被调用:

  <script>
  $(function() {
    $( "#dialog-message" ).dialog({
      modal: true,
      buttons: {
        Ok: function() {
          $( this ).dialog( "close" );
        }
      }
    });
  });
  </script>
</head>
<body>
<div id="dialog-message" title="Download complete">
  <p>
    <span class="ui-icon ui-icon-circle-check" style="float:left; margin:0 7px 50px 0;"></span>
    Your files have downloaded successfully into the My Downloads folder.
  </p>
  <p>
    Currently using <b>36% of your storage space</b>.
  </p>
</div>

但是我想做的是创建2个参数:1接收一些文本,第二个是当我按下ok时,它会转到一个链接。

我正在开发一个网站,我不想使用浏览器警报,只是想使用JQuery脚本和做这样的事情:

<?php
    function alerta($texto="",$redirect=""){
        print("<Script language=javascript>");
        if($texto!="")
            print("alert('"$texto'");");
        if($redirect!="")
            print("window.location='"$redirect'";");
        print("</script>");
    }
?>

你可以在div模态中回复你的文本(变量1),然后在'OK'按钮上使用重定向函数单击事件:

$(function() {
     $( "#dialog-message" ).dialog({
       modal: true,
       buttons: {
         Ok: function() {
              window.location = "$YOUR_VARIABLE_2";
         }
       }
    });
});