Este artículo describe el método para implementar el cuadro desplegable Seleccionar con la función de entrada en JS. Compártelo para su referencia. El método de implementación específico es el siguiente:
Método de implementación uno
Copie el código de la siguiente manera: <html>
<Evista>
<Meta http-oquiv = 'content-type' content = 'text/html; charset = GB2312 '>
<title> JS implementa un cuadro desplegable Intryable </title>
</ablo>
<Body>
<div style = "Posición: relativo;">
<span style = "margen-izquierda: 100px; ancho: 18px; desbordamiento: oculto;">
<select onchange = "this.parentnode.nextsibling.value = this.value">
<opción valor = "Alemania"> Alemania </opción>
<opción valor = "noruega"> noruega </ppection>
<opción valor = "switzerland"> Suiza </ppection>
</select> </span> <input name = "box">
</div>
</body>
</Html>
Método de implementación dos
Copie el código de código de la siguiente manera: <select id = "select" onkeydown = "select.del (this, evento)" onKeyPress = "select.write (this, evento)">
<opción valor = ""> </opción>
<opción valor = "aaa"> aaa </ppection>
<opción valor = "bbb"> bbb </ppection>
<opción valor = "ccc"> ccc </opción>
</select>
<input type = "button" value = "get Selection Value" id = "test" onClick = "test ();"/>
<script>
var select = {
del: function (obj, e) {
if ((e.keycode || e. which || e.charcode) == 8) {
var opt = obj.options [0];
opt.text = opt.value = opt.value.substring (0, opt.value.length> 0? opt.value.length-1: 0);
}
},
escribir: function (obj, e) {
if ((e.KeyCode || E. which || e.charcode) == 8) return;
var opt = obj.options [0];
opt.selected = "seleccionado";
opt.text = opt.value += strome.FromCharCode (E.CharCode || E. Which || E.KeyCode);
}
}
función test () {
alerta (document.getElementById ("Seleccionar"). Valor);
}
</script> <r />
Espero que este artículo sea útil para la programación de JavaScript de todos.