我有一个小难题。我有一个 Jquery/Js 函数,它可以从 DropDownList 中选择项目。然后将其分配给一个变量,并将该变量传递给另一个函数。我遇到的唯一问题是,当我第一次这样做时,一切正常。当我第二次调用该函数时,变量保持不变而不是重新分配。
ddlCaseFilesNew、ddlCaseFilesOld 是我的两个 DropDownList。
这是我的功能:
function getCaseFiles(canMoveExpenses) {
//create Popup with content from div
var newCaseDdl = null;
var oldCaseDdl = null;
$('#ddlFiles').dialog({
autoOpen: true,
height: 'auto',
width: 'auto',
modal: true,
buttons: {
"Ok": function () {
//assign new CaseFile and old CaseFile for stored proc.
//var newCaseDdl = "";
newCaseDdl = $("#ddlCaseFilesNew").val();
alert("newCaseDdl = " + newCaseDdl);
// newCaseDdlInt = newCaseDdl.options[newCaseDdl.selectedIndex].value;
//var oldCaseDdl = "";
oldCaseDdl = $("#ddlCaseFilesOld").val();
// oldCaseDdlInt = oldCaseDdl.options[oldCaseDdl.selectedIndex].value;
alert("oldCaseDdl" + oldCaseDdl);
if (newCaseDdl != -1 && oldCaseDdl != -1) {
moveCasefile(canMoveExpenses, newCaseDdl, oldCaseDdl);
$(this).dialog('close');
}
else {
showMessage("Error. Please Select a Value From The Lists.");
}
oldCaseDdl = $("#ddlCaseFilesOld").selectedIndex = -1;
newCaseDdl = $("#ddlCaseFilesNew").selectedIndex = -1;
},
Cancel: function () {
newCaseDdl = null;
oldCaseDdl = null;
$(this).dialog('close');
}
}
});
}
我对 Js/JQuery 有点陌生
oldCaseDdl 和 newCaseDdl 是需要更改 DropDownList 的选定索引的变量