怎么制作自动查询?
就是自己不用输入,当有输入数值时候自己查询数据库...
------解决方案--------------------离开文本框时,触发查询数据库的动作是不.
------解决方案--------------------可以离开文本框时查询,也可以当文本内容改变时查询!
csdn的:
<input type= "text " name= "TopicName " onkeydown= "keydown() " onkeyup= "keypress(this) " onblur= "keypress(this) " size= "100 " maxlength= "128 " style= "width: 100% ">
function Search()
{
document.SearchForm.submit();
}
//fot relation topic
//author: meizz
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[i].url + " ' target= '_blank '> "+ a[i].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);
}