我有这样的代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Eg - Textbox Dropdown</title>
</head>
<body>
<input name="TextboxExample" type="text" maxlength="50" id="TextboxExample" tabindex="2"
onchange="DropDownIndexClear('DropDownExTextboxExample');" style="width: 242px;
position: absolute; top: 0px; left: 0px; z-index: 2;" />
<select name="DropDownExTextboxExample" id="DropDownExTextboxExample" tabindex="1000"
onchange="DropDownTextToBox(this,'TextboxExample');" style="position: absolute;
top: 0px; left: 0px; z-index: 1; width: 265px;">
<option value="Value for Item 1" title="Title for Item 1">Item 1</option>
<option value="Value for Item 2" title="Title for Item 2">Item 2</option>
<option value="Value for Item 3" title="Title for Item 3">Item 3</option>
</select>
<script language="javascript" type="text/javascript">
//Since the first <option> will be preselected the IndexClear function must fire once to clear that out.
DropDownIndexClear("DropDownExTextboxExample");
</script>
</div>
</body>
</html>
<script type="text/javascript">
function DropDownTextToBox(objDropdown, strTextboxId) {
document.getElementById(strTextboxId).value += objDropdown.options[objDropdown.selectedIndex].value.concat(',');
DropDownIndexClear(objDropdown.id);
document.getElementById(strTextboxId).focus();
}
function DropDownIndexClear(strDropdownId) {
if (document.getElementById(strDropdownId) != null) {
//document.getElementById(strDropdownId).selectedIndex = -1;
var x=document.getElementById("DropDownExTextboxExample");
x.remove(x.selectedIndex);
}
}
</script>
该代码工作正常,但我需要避免一次又一次地选择相同的记录。
例如:如果我从下拉列表中选择第 1 项,则不应再次选择它。现在在这种情况下,我可以选择项目 1 'n' 次。
我在这里需要帮助。
谢谢韩