In diesem Artikel wird die Methode zur Implementierung des Dropdown-Felds ausgewählt mit Eingabefunktion in JS implementiert. Teilen Sie es für Ihre Referenz. Die spezifische Implementierungsmethode lautet wie folgt:
Implementierungsmethode eins
Kopieren Sie den Code wie folgt: <html>
<kopf>
<Meta http-äquiv = 'content-type' content = 'text/html; charSet = gb2312 '>
<titels> js implementiert eingabebedingbares Dropdown-Feld </title>
</Head>
<body>
<div style = "Position: relativ;">
<span style = "margin-links: 100px; width: 18px; Überlauf: versteckt;">
<auswählen onchange = "this.parentnode.nextsibling.Value = this.value">
<Option Value = "Deutschland"> Deutschland </Option>
<Option Value = "Norway"> Norwegen </Option>
<Option Value = "Schweiz"> Schweiz </Option>
</select> </span> <input name = "box">
</div>
</Body>
</Html>
Implementierungsmethode zwei
Kopieren Sie den Code -Code wie folgt: <select id = "select" onkeydown = "select.del (this, Ereignis)" OnKeypress = "select.write (this, Ereignis)">
<Option Value = ""> </Option>
<Option value = "aaa"> aaa </option>
<Option Value = "BBB"> BBB </option>
<Option Value = "CCC"> CCC </Option>
</select>
<input type = "button" value = "Auswahlwert erhalten" 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);
}
},
Schreiben: Funktion (obj, e) {
if ((e.keycode || e. was || e.charcode) == 8) zurücksend;
var opt = obj.options [0];
opt.Selected = "ausgewählt";
opt.Text = opt.value += string.fromCharCode (E.Charcode || E.Which || E.KeyCode);
}
}
Funktionstest () {
alert (document.getElementById ("select"). value);
}
< /script> <br />
Ich hoffe, dieser Artikel wird für JavaScript -Programme aller hilfreich sein.