當我通過Stackoverflow和Google搜索時,找不到解決方案來簡化我的代碼(或者我沒有找到確切的搜索詞)。它真的讓我感到困惑,我無法簡化下面的代碼。簡化多個jQuery對話框函數
因爲我是這個領域的初學者,所以我不得不重複所有相同的代碼,當我可以結合的相似之處。
非常感謝您的幫助!
$('.detail-view').dialog({
autoOpen: false,
draggable: false,
resizable: false,
closeOnEscape: true,
modal: true,
height: 'auto',
width: 600,
position: ['top', 150] });
$('.forgotpass').dialog({
autoOpen: false,
draggable: false,
resizable: false,
closeOnEscape: true,
modal: true,
height: 'auto',
width: 400,
position: ['top', 150] });
$('.user0').load('php/usersetting.php').dialog({
autoOpen: true,
draggable: false,
resizable: false,
closeOnEscape: false,
modal: true,
height: 'auto',
width: 500,
position: ['top', 150],
open: function(){
$(this).parent().find('.ui-dialog-titlebar-close').hide();
} });
$('.user1').load('php/usersetting.php').dialog({
autoOpen: false,
draggable: false,
resizable: false,
modal: true,
height: 'auto',
width: 500,
position: ['top', 100] });
$('.user2').load('php/usersetting.php').dialog({
autoOpen: true,
draggable: false,
resizable: false,
closeOnEscape: true,
modal: true,
height: 'auto',
width: 500,
position: ['top', 150],
open: function(){
$(this).parent().find('.ui-dialog-titlebar-close').hide();
}
});
從一個基本對象開始,然後使用'$ .extend()'來進行變化。另外,利用'''in selector語法來組合不同的調用。 – Pointy