Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
183 views
in Technique[技术] by (71.8m points)

Html select keystroke timeout

I'm creating a standard html select dropdown with a hundred or so entries. My users would like to be able to type in the value to get to the proper selection faster. While this is supported natively, the keystroke timeout is very quick, so if you don't type the string quickly, you end up with the wrong selection. Is there a way to increase the timeout? Or has anyone written code to do this manually?

Here's a jsFiddle to illustrate the issues. JsFiddle

label for="title">Choose your poison</label>
<select id="title" name="title">
 <option value="Cider" selected>Apple Cider</option>
 <option value="Juice">Apple Juice</option>
 <option value="Curacao">Curacao</option>
 <option value="Jack">Jack's Hard Cider</option>
 <option value="Jake">Jake's Hard Cider</option>
 <option value="James">James' Hard Cider</option>
 <option value="Jamison">Jamison Irish Whiskey</option>
 <option value="Kool">Kool Ade</option>
 <option value="Lemonade">Lemonade</option>
 <option value="Prune">Prune Juice</option> 
</select>

Try selecting the Jack's or Jake's by slowly typing and see if you end up selecting Curacao or Kool Ade.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You could use a <datalist> instead. It's supported in IE10 and higher. MDN Page

DEMO

<label for="poison">Choose your poison</label>
<input id="poison" name="poison" list="poisons" />

<datalist id="poisons">
    <option value="Cider" selected>Apple Cider</option>
    <option value="Juice">Apple Juice</option>
    <option value="Curacao">Curacao</option>
    <option value="Jack">Jack's Hard Cider</option>
    <option value="Jake">Jake's Hard Cider</option>
    <option value="James">James' Hard Cider</option>
    <option value="Jamison">Jamison Irish Whiskey</option>
    <option value="Kool">Kool Ade</option>
    <option value="Lemonade">Lemonade</option>
    <option value="Prune">Prune Juice</option>
</datalist>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...