2

我正在尝试使用 Jquery 加载两个模式对话框。它们都使用 ajax 加载单独的页面。唯一的问题是其中只有一个有效。

我想我需要简化我的代码,但不确定如何。

    <script type="text/javascript">
$(document).ready(function(){
var dialogOpts = {
      modal: true,
      bgiframe: true,
      autoOpen: false,
      height: 400,
      width: 550,
      draggable: true,
      resizeable: true,
      title: "Your campaign rates",
   };
$("#ratesbox").dialog(dialogOpts);   //end dialog

   $('#ratesbutton').click(
      function() {
         $("#ratesbox").load("rate_sheet/index.php", [], function(){
               $("#ratesbox").dialog("open");
            }
         );
         return false;
      }
   );
}); 
</script>


<script type="text/javascript">
$(document).ready(function(){
var dialogOptsPass = {
      modal: true,
      bgiframe: true,
      autoOpen: false,
      height: 400,
      width: 550,
      draggable: true,
      resizeable: true,
      title: "Change your pasword",
   };
$("#passwordbox").dialog(dialogOptsPass);   //end dialog

   $('#passwordbutton').click(
      function() {
         $("#passwordbox").load("change_password/index.php", [], function(){
               $("#passwordbox").dialog("open");
            }
         );
         return false;
      }
   );
}); 
</script>

可以结合两个脚本吗????

4

1 回答 1

3

您可以稍微简化一下脚本,如下所示:

$(function(){
  var dialogOpts = {
        modal: true,
        bgiframe: true,
        autoOpen: false,
        height: 400,
        width: 550,
        draggable: true,
        resizeable: true,
        title: "Your campaign rates"
     };
  $("#ratesbox, #passwordbox").dialog(dialogOpts);
  $("#passwordbox").dialog("option", "title", "Change your pasword");
  //or...
  //$("#ratesbox").dialog(dialogOpts);
  //$("#passwordbox").dialog($.extend(dialogOpts, { title: "Change your pasword" }));

   $('#ratesbutton').click(function() {
     $("#ratesbox").load("rate_sheet/index.php", function(){
       $("#ratesbox").dialog("open");
     });
     return false;
   });
   $('#passwordbutton').click(function() {
     $("#passwordbox").load("change_password/index.php", function(){
       $("#passwordbox").dialog("open");
     });
     return false;
   });
});

...但是我没有看到您的代码有任何特殊问题(除了一个应该导致两者都出现问题的问题),它很可能与您的标记有关,即为什么一个不起作用。还要确保删除对象声明中的尾随逗号,你目前有title: "Your campaign rates",......那里没有悬空的逗号,特别是 IE 会炸毁垫圈,吃掉你的猫并偷走你的车。

于 2010-05-31T12:16:24.847 回答