analysis code paragraphs using(DOM of javascript ,timer,ajax)

H

hzq3554055

i am novice,guess the following code can work combineing with server-
side code ,but chaos ï¼›somewhere to me is great<script>
var relationObject = {timer: null, key: ""};
function TopicToString(a)
{
relationObject[relationObject.key] = a;
var dl = document.getElementById("relationTopic");
//dl.style.display = a.length>0 ? "" : "none";
var dd = document.getElementById("relationList");
dd.innerHTML = "";
if(a.length==0) return;
var ul = document.createElement("UL");
for(var i=0; i<a.length; i++)
{
var li = document.createElement("LI");
li.innerHTML = "<a href='"+ a.url +"' target='_blank'>"+
a.title +"</a>";
ul.appendChild(li);
}
dd.appendChild(ul);
var div = document.createElement("DIV");
div.style.textAlign = "right";
div.style.paddingRight = "5px";
div.innerHTML = "<a style='color: #025c67' href='http://
community.csdn.net/ShortAsk/ShortAskMore.aspx?title="+
escape(relationObject.key) +"' target='_blank'>更多相关问题...</a>";
dd.appendChild(div);
}
function getRelation(str)
{
if(relationObject[str])
{
relationObject.key = str;
TopicToString(relationObject[str]);
return;
}
var dataurl = "http://community.csdn.net/ShortAsk/ShortAsk.aspx";
var qs = "?title="+ escape(str);
qs += "&count=10";
qs += "&callback=TopicToString";
var s = document.createElement("SCRIPT");
s.type = "text/javascript";
s.src = dataurl + qs;
s.charset = "GB2312";
window["_run"] = true;
setTimeout('window["_run"]=false', 1000);
relationObject.key = str;
document.getElementsByTagName("HEAD")[0].appendChild(s);
}
function keydown()
{
clearTimeout(relationObject.timer);
}
function keypress(input)
{
if(input.value.length<2 || window["_run"]) return;
relationObject.timer = setTimeout(function()
{getRelation(input.value)}, 2000);
}
//end
// --></SCRIPT>



<TD class=relationTopic vAlign=top>
<DL id=relationTopic>
<DT>相关问题列表
<DD id=relationList>输入问题,<BR>问题答案立å³å‘ˆçŽ°åœ¨æ‚¨çœ¼å‰ï¼ </DD></DL></
TD>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,981
Messages
2,570,188
Members
46,732
Latest member
ArronPalin

Latest Threads

Top