0

而不是一直使用修剪,我想在下面的代码中使用一次......请帮助我

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?";
}
4

4 回答 4

3

将其存储在变量中:

 var selectedValue = $.trim(selectedValue);

然后做:

if (selectedValue == "Oppty Locations") {

}

ETC...

于 2013-03-13T09:52:31.430 回答
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?";
}
于 2013-03-13T09:53:39.937 回答
1

用修剪后的值覆盖 selectedValue 并随后使用,或将其分配给某个变量并使用它。

selectedValueTrimmed = $.trim(selectedValue)
if("Company Profile"==selectedValueTrimmed ){
于 2013-03-13T09:52:26.247 回答
0

将其改为 Switch 语句而不是 Else If 语句。

switch ($.trim(selectedValue)) {
    case: "Company Profile" 
        actionClass = "locationImportCompany.do?";
        break;
    case: "Oppty Locations" 
        actionClass = "locationImport.do?";
        break;
   // So on ...
} 
于 2013-03-13T10:12:51.647 回答