我必须使用两个自动完成的盒子,但只有第一个盒子可以使用。两个字段的关键字相同,例如一个自动完成字段用于location-1,另一个用于location-2。 以下是一个自动完成字段框的工作代码:
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var data = ["Boston Celtics", "Chicago Bulls", "Miami Heat", "Orlando Magic", "Atlanta Hawks", "Philadelphia Sixers", "New York Knicks", "Indiana Pacers", "Charlotte Bobcats", "Milwaukee Bucks", "Detroit Pistons", "New Jersey Nets", "Toronto Raptors", "Washington Wizards", "Cleveland Cavaliers"];
$("#seed_one").autocomplete({source:data});
});
</script>
</head>
<body>
<input id="seed_one" type="text" name="seed_one"/>
</body>
</html>
答案 0 :(得分:2)
对于另一个自动填充框,您已创建另一个输入框并将其id
传递给autocomplete
函数。
<script type="text/javascript">
$(document).ready(function(){
var data = ["Boston Celtics", "Chicago Bulls", "Miami Heat", "Orlando Magic", "Atlanta Hawks", "Philadelphia Sixers", "New York Knicks", "Indiana Pacers", "Charlotte Bobcats", "Milwaukee Bucks", "Detroit Pistons", "New Jersey Nets", "Toronto Raptors", "Washington Wizards", "Cleveland Cavaliers"];
$("#seed_one").autocomplete({source:data});
$("#seed_two").autocomplete({source:data});
});
</script>
<body>
<input id="seed_one" type="text" name="seed_one"/>
<input id="seed_two" type="text" name="seed_two"/>
</body>