我有一个文本框、一个搜索按钮和一个页面中的大量文本。我想要做的是,我想在文本框中输入一个字符串,然后单击搜索按钮。当我这样做时,我希望在该页面中突出显示所有结果。我如何实现这一目标?
这是我的代码的 POC-
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Auto Completion</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.8.3.js"></script>
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<%
List<String> strList = new ArrayList<String>();
strList.add("\"red\"");
strList.add("\"orange\"");
strList.add("\"blue\"");
strList.add("\"pink\"");
strList.add("\"brown\"");
strList.add("\"yellow\"");
strList.add("\"violet\"");
strList.add("\"indigo\"");
strList.add("\"green\"");
strList.add("\"grey\"");
strList.add("\"black\"");
%>
<script>
$(function() {
var availableTags = <%=strList.toString() %>;
$( "#tags" ).autocomplete({
source: availableTags
});
});
</script>
<script>
function selected () {
// What to do?
}
</script>
</head>
<body>
<%=strList.toString()%>
<div class="ui-widget">
<label for="tags">Tags: </label>
<input id="tags" />
<input type="button" onclick="javascript:selected();" value="Search"/>
</div>
</body>
</html>