如何通过点击第一个字母选择select标签中的选项

时间:2015-01-05 09:17:52

标签: javascript html

我在html中有一个select标签,有以下5个选项: - " Bangalore"," Mumbai"," Delhi"," Hyderabad& #34;," Pune"。当用户键入' B'在键盘上它应该显示'班加罗尔' ,当用户输入' D'时,它应该显示德里,就像其他人一样,当用户键入选项的第一个字母时,它应该显示相应的选项。我是怎么用html做的。

3 个答案:

答案 0 :(得分:1)

试试这个:(HTML5)

<input list="browsers">

<datalist id="browsers">
  <option value="Internet Explorer">
  <option value="Firefox">
  <option value="Chrome">
  <option value="Opera">
  <option value="Safari">
</datalist>

答案 1 :(得分:0)

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Autocomplete - Default functionality</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<script>
$(function() {
var availableTags = [
  "Bangalore",
  "Mumbai",
  "Delhi",
  "Hyderabad",
  "Pune"
];
$( "#tags" ).autocomplete({
  source: availableTags
});
});
</script>
 </head>
<body>

 <div class="ui-widget">
 <label for="tags">Tags: </label>
 <input id="tags">
 </div>
 </body>
 </html>

答案 2 :(得分:0)

&#13;
&#13;
<input list="city">
        <datalist id="city">
        <option value="Bangalore">
        <option value="Mumbai">
        <option value="Delhi">
        <option value="Hyderabad">
        <option value="Pune">
    </datalist>
&#13;
&#13;
&#13;

<input list="city">
    <datalist id="city">
    <option value="Bangalore">
    <option value="Mumbai">
    <option value="Delhi">
    <option value="Hyderabad">
    <option value="Pune">
</datalist>