0

I am a beginner at HTML and javascript so apologies if the questions below appear obvious. I am trying to implement instant search in a website with pure java script but I have a few questions.

Right now I plan to have a function respond to each onkeyup event. Making use of AJAX, the function will contact a server which returns links separated by a newline character. now the questions: If the text returned by the server is already in the form of html links and paragraphs, is there a way I can insert it after the html input text box? If so how can I do this? I have found references to createElement() and appendChild() methods but am not sure how they work. Also, people have suggested using a tag but I have never used this in html and am not sure what it is.

If the above is not possible I was thinking of doing the following, When the text is returned by the server, 1. use String.split() to turn the returned text into an array of results. 2. for each element in the array 3. Create an element and insert it . (still need to check exactly how to do this). 4. end for

A problem being is that I would need a quick way of clearing the previous search results each time a key would be pressed.

Any help is greatly appreciated.

4

1 回答 1

0

最好的方法是通过 Json 返回。Json 将有所有搜索结果,您可以通过http://www.json.org/js.html轻松使用 Json

这将是代替拆分内容的好方法。

于 2013-04-30T12:21:56.930 回答