var defaults = { width: "auto",//Default or automatically set width highlightColor: "#3399FE",//Color when highlighting unhighlightColor: "# FFFFFF",//Color when not highlighted css: cssOptions, dataType: "xml",//Ajax request return data type paramName: "word",//Ajax request parameter name , if you have set the id of the text field, then use this attribute delay: 500, //When the text field is continuously input, how often ajax requests the server };
keys is the value corresponding to the keyboard key; autocomplete is the function called, in which you can set the URL of the ajax request and configure the parameters that appear in the defaults above. This method returns the value of the text field; autoTipTemplate is the prompt box and prompt menu displayed when inputting, and returns a jquery object; select is the selection prompt menu, which is the highlighted option of the prompt menu. The target is of course the target object, and the index is the one that will be highlighted. The index of the bright option, settings is the highlight color configuration, which is included in the defaults. The properties of the defaults object are assigned to the settings object through the $.extend method; keyOperator is a keyboard operation for the text field. This is the core function; operation prompts and automatic completion depend on it; See below Look at the html code and see how the autocomplate plug-in is called:
Ajax example, implementing Google Search completion function
Please enter:
Look at this code. AutocomplataWordServlet is the requested Servlet. dataType is the type of data returned by the ajax request server. width can set the width of the automatic prompt menu. How about it? It’s relatively simple to use. Of course, you can also add other configurations later, such as: Code snippet
There is nothing to say, just get the keywords of the ajax request in the client text field, and then perform word filtering in the jsp page. However, you can also use regular on the client or regular filtering on the server. Look at the content of word.jsp below:
is a document in xml format. By using jstl expression and matching with startsWith function, if passed, it will appear in the xml content, and you can see the above contentType="text/xml; charset=UTF- 8"? It's text/xml! Please note this, some browsers will not be able to parse it if it is not configured. Author: hoojo blog: http://blog.csdn.net/IBM_hoojo
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn