Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Using Autocompleter comes in two flavors. One, named Autocompleter. Local, keeps an array of possible suggestions for instantaneous feedback. The other, Ajax. Autocomleter, relies on a remote server to give it suggestions - making an Ajax call whenever suggestion need to be retrieved | CHAPTER 12 ADVANCED CONTROLS AUTOCOMPLETERS IN-PLACE EDITORS AND SLIDERS 279 Using Autocompleter Autocompleter comes in two flavors. One named Autocompleter.Local keeps an array of possible suggestions for instantaneous feedback. The other Ajax.Autocompleter relies on a remote server to give it suggestions making an Ajax call whenever suggestions need to be retrieved. Naturally Autocompleter.Local has less overhead since it does not need to talk to the server as a result its suggestions will usually appear far more quickly. You ll only want to fall back to Ajax.Autocompleter if the pool of suggestions is simply too large to keep on the client side or if the logic for picking suggestions is more complicated than an ordinary string match. We ll cover these cases several pages from now but for now let s use the local version for simplicity s sake. Using Autocompleter.Local The syntax for declaring a new Autocompleter.Local is new Autocompleter.Local inputElement updateElement array options where inputElement is the text box updateElement is the element that will hold the suggestions array is the list of possible suggestions and options is the configuration object we ve come to know so well. Let s add a script tag to the page and declare an Autocompleter.Local on page load script type text javascript document.observe dom loaded function new Autocompleter.Local player_name player_suggestions James Polk James Buchanan Franklin Pierce Millard Fillmore Warren Harding Chester Arthur Rutherford Hayes Martin Van Buren script Our array contains a short list of nonnotable American presidents the benchwarmers of our fictional league. Rather than make the user choose from an endless drop-down menu or force her to remember how many Is are in Fillmore Autocompleter will offer possible name completions after only a few keystrokes. Save index.html and open it in a browser. You ll see a text box of course as shown in Figure 12-1. 280 CHAPTER 12 ADVANCED CONTROLS AUTOCOMPLETERS .