Home > Web Front-end > JS Tutorial > Use js to implement an editable select drop-down list_javascript skills

Use js to implement an editable select drop-down list_javascript skills

WBOY
Release: 2016-05-16 16:58:54
Original
1139 people have browsed it
Copy code The code is as follows:



<script> <br>function clearSelect(obj,e) <br>{ <br>opt = obj.options[0] ; <br>opt.selected = "selected"; <br>if((e.keyCode== 8) ||(e.charCode==8))//Use the backspace key to delete word by word Edit function <br>{ <br>opt.value = opt.value.substring(0, opt.value.length>0?opt.value.length-1:0); <br>opt.text = opt.value ; <br>} <br>if((e.keyCode== 46) ||(e.charCode==46))//Use the Delete key to implement the editing function of verbatim deletion<br>{ <br>opt.value = ""; <br>opt.text = opt.value; <br>} <br>//You can also implement other key press responses<br>} <br><br>function writeSelect(obj, e) <br>{ <br>opt = obj.options[0]; <br>opt.selected = "selected"; <br>opt.value = String.fromCharCode(e.charCode||e.keyCode); <br>opt.text = opt.value; <br>} <br>function forbidBackSpace()//In order to avoid the backspace return to the previous page function in IE, which conflicts with the editing function of this drop-down box, it needs to be disabled backspace function. forbidBackSpace can be written in <body onkeydown="forbidBackSpace();">. <br>{ <br>if((event.keyCode == 8) && (event.srcElement.type != "text" && event.srcElement.type != "textarea" && event.srcElement.type != "password ")) <br>{ <br>event.keyCode = 0; <br>event.returnValue = false; <br>} <br>} <br></script>
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template