我正在尝试使用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>

结合两个脚本是否可以选择????

有帮助吗?

解决方案

您可以将脚本简化一些,这样:

$(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",...在那里不要悬空的逗号,即特别是会吹垫圈,吃猫并偷走了你的汽车。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top