2010-05-31 94 views
2

我想用Jquery加載兩個模態對話框。他們都使用ajax加載單獨的頁面。唯一的問題是隻有其中一個工作。簡化Jquery代碼幫助!

我想我需要簡化我的代碼,但我不確定如何。

<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> 

它是更多鈔票兩個腳本合併????

+0

你試過了嗎? – vladv 2010-05-31 12:12:35

+0

我很好奇以誰的形式提問這個問題 – jAndy 2010-05-31 12:14:28

+0

@jAndy:我們可以稱它爲投票限制嗎? – 2010-05-31 12:26:14

回答

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會吹一個墊片,吃掉你的貓並偷走你的車。

+1

+1爲貓吃,偷車IE – jAndy 2010-05-31 12:21:19

+0

+1 IE對我也是這樣!除了沒有許可證,所以當它被拖延時,我得到了票! #%@ $$#$! – Mottie 2010-05-31 13:08:03