Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/237.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
避免从下拉Javascript PHP中复制记录_Php_Javascript_Html_Javascript Events - Fatal编程技术网

避免从下拉Javascript PHP中复制记录

避免从下拉Javascript PHP中复制记录,php,javascript,html,javascript-events,Php,Javascript,Html,Javascript Events,我有这样的代码 <!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

我有这样的代码

        <!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>

Eg-文本框下拉列表
项目1
项目2
项目3
//由于第一个将被预选,IndexClear函数必须触发一次才能清除。
DropDownIndexClear(“DropDownExtBoxesExample”);
函数DropDownTextToBox(objDropdown,strTextboxId){
document.getElementById(strTextboxId).value+=objDropdown.options[objDropdown.selectedIndex].value.concat(',');
DropDownIndexClear(objDropdown.id);
getElementById(strTextboxId).focus();
}
函数DropDownIndexClear(strDropdownId){
if(document.getElementById(strDropdownId)!=null){
//getElementById(strDropdownId).selectedIndex=-1;
var x=document.getElementById(“DropDownExtBoxesExample”);
x、 移除(x.selectedIndex);
}
}
代码运行良好,但我需要避免同一条记录,才能一次又一次地被选中

例如:如果我从下拉列表中选择项目1,则不应再次选择它。现在,在这种情况下,我可以选择“n”次的项目1

我需要帮助

谢谢 哈恩


选择项
项目1
项目2
项目3

选择项
项目1
项目2
项目3

您可以将项目禁用一次

您可以将项目禁用一次

function remove_this_item(){
   var htmlSelect=document.getElementById('DropDownExTextboxExample');
   var optionToRemove=htmlSelect.options.selectedIndex;
   htmlSelect.remove(optionToRemove);
   return true;
}
您可以在这里查看:


您可以在此处查看:

您想让我删除此行文档。getElementById(strDropdownId)。selectedIndex=-1??我不明白你的意思。谢谢您的即时帮助。是的,请从选择框中删除该选项。我已编辑代码,但第一个值未被选中,这对u是否有任何问题。你能帮我解决这个问题吗?你能在JSFIDLET中创建一个链接吗?你想让我删除这行文档。getElementById(strDropdownId)。selectedIndex=-1??我不明白你的意思。谢谢您的即时帮助。是的,请从选择框中删除该选项。我已编辑代码,但第一个值未被选中,这对u是否有任何问题。您能帮我解决这个问题吗PSRcan u在JSFIDDLET中创建一个链接让我们编辑我的代码,但是下拉列表中的第一个值没有被选中:(编辑了我的代码,但未选择下拉列表中的第一个值:(
function remove_this_item(){
   var htmlSelect=document.getElementById('DropDownExTextboxExample');
   var optionToRemove=htmlSelect.options.selectedIndex;
   htmlSelect.remove(optionToRemove);
   return true;
}