1

我有这样的代码

        <!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' 次。

我在这里需要帮助。

谢谢韩

4

3 回答 3

1
<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="">Select Item</option>
        <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>
于 2013-05-10T05:54:31.027 回答
0

您可以在选择后永久禁用该项目

于 2013-05-10T06:03:28.480 回答
0
function remove_this_item(){
   var htmlSelect=document.getElementById('DropDownExTextboxExample');
   var optionToRemove=htmlSelect.options.selectedIndex;
   htmlSelect.remove(optionToRemove);
   return true;
}

你可以在这里查看:http: //jsfiddle.net/3fkNL/2/

于 2013-05-10T06:18:48.740 回答