我有一个带有自动完成功能的基本文本框,其中列出了彩虹的颜色,但我想更改它,以便当您选择一种颜色时,它会以该颜色出现(即,红色这个词是红色的)但我不能弄清楚怎么做。
继承人的代码:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>jQuery UI Autocomplete - Default functionality</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<script>
$(function () {
var colours = [
"red",
"orange",
"yellow",
"green",
"blue",
"indigo",
"violet",
]
$("#rainbow1").autocomplete({
source: colours
});
});
</script>
</head>
<body>
<div class="ui-widget">
<label for="rainbow1" style="color:red">Rainbow1: </label>
<input type="text" id="rainbow1" /> </br>
</div>
</body>
</html>