简化Jquery代码帮助!
问题描述:
我想用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>
它是更多钞票两个脚本合并????
答
您可以简化您的脚本了一点,像这样:
$(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会吹一个垫片,吃掉你的猫并偷走你的车。
你试过了吗? – vladv 2010-05-31 12:12:35
我很好奇以谁的形式提问这个问题 – jAndy 2010-05-31 12:14:28
@jAndy:我们可以称它为投票限制吗? – 2010-05-31 12:26:14