2013-03-13 50 views
0

,而不是使用修剪所有我想用一次作为共同为下面的代码的时候...请帮助我jQuery中使用装饰

if ("Company Profile" == $.trim(selectedValue)) { 
    actionClass = "locationImportCompany.do?"; 
} else if ("Oppty Locations" == $.trim(selectedValue)) { 
    actionClass = "locationImport.do?"; 
} else if ("Different Oppty" == $.trim(selectedValue)) { 
    actionClass = "locationImportDiffOppty.do?"; 
} else if ("Loop TrackId Profile" == $.trim(selectedValue)) { 
    actionClass = "locationImportLoopTrkId.do?"; 
} else if ("Inventory" == $.trim(selectedValue)) { 
    isOrdering = "Y"; 
    actionClass = "inventoryLaunch.do?"; 
} else if ("Data Center List" == $.trim(selectedValue)) { 
    actionClass = "locationImportDataCenter.do?"; 
} else if ("Customer AccountId" == $.trim(selectedValue)) { 
    actionClass = "inventoryLaunch.do?"; 
} else if ("Customer Name" == $.trim(selectedValue)) { 
    actionClass = "locationImportDataCenter.do?"; 
} 
+0

其中是代码???? – 2013-03-13 09:53:07

回答

1

在写了selectedValue与修整值,之后使用,或者将其指定到一些变量并使用它。

selectedValueTrimmed = $.trim(selectedValue) 
if("Company Profile"==selectedValueTrimmed){ 
3

储存于一个变量:

var selectedValue = $.trim(selectedValue); 

然后做:

if (selectedValue == "Oppty Locations") { 

} 

等等

+0

PS所有这些如果的,但如果使用的查找对象1可能被替换。 – QuentinUK 2013-03-13 10:11:17

2
var selectedValue = $.trim(selectedValue); 
if ("Company Profile" == selectedValue) { 
    actionClass = "locationImportCompany.do?"; 
} else if ("Oppty Locations" == selectedValue) { 
    actionClass = "locationImport.do?"; 
} else if ("Different Oppty" == selectedValue) { 
    actionClass = "locationImportDiffOppty.do?"; 
} else if ("Loop TrackId Profile" == selectedValue) { 
    actionClass = "locationImportLoopTrkId.do?"; 
} else if ("Inventory" == selectedValue) { 
    isOrdering = "Y"; 
    actionClass = "inventoryLaunch.do?"; 
} else if ("Data Center List" == selectedValue) { 
    actionClass = "locationImportDataCenter.do?"; 
} else if ("Customer AccountId" == selectedValue) { 
    actionClass = "inventoryLaunch.do?"; 
} else if ("Customer Name" == selectedValue) { 
    actionClass = "locationImportDataCenter.do?"; 
} 
0

使其代替switch语句中否则如果声明。

switch ($.trim(selectedValue)) { 
    case: "Company Profile" 
     actionClass = "locationImportCompany.do?"; 
     break; 
    case: "Oppty Locations" 
     actionClass = "locationImport.do?"; 
     break; 
    // So on ... 
}