日期:2014-05-18  浏览次数:20448 次

怎么实现2个文本框的ajax 自动补全啊???
小弟写了一个ajax信息自动补全的例子:怎么实现2个文本框的补全啊??
<script   language= "javascript "   type= "text/javascript ">
  function   mainLoop()
{
//val   =   escape(queryField.value);
val   =   queryField.value;
if   (lastVal   !=   val)
{
var   response   =   AjaxMethod.GetSearchItems(val);
showQueryDiv(response.value);
lastVal   =   val;
}
setTimeout( 'mainLoop() ',100);
return   true;
}

</script>

</head>
<body     onload= "javascript:InitQueryCode( 'TextBox1 ') ">
<form   id= "Form1 "   method= "post "   runat= "server ">
        <asp:TextBox   ID= "TextBox1 "     runat= "server "> </asp:TextBox>
</form>
</body>


------解决方案--------------------
你的问题涉及两部:
AJAX取相关信息

文本框自动补齐

----------
var intIndex = 0;
var intMouseX;
var intMouseY;
var intDivShowFlag = 0;
var intTextShowFlag = 0;

function InitSmartPromptList(arrList)
{
if (arrList.constructor != Array)
{
return;
}

arrList.sort
(
function(a, b)
{
if(a.length> b.length)
{
return 1;
}
else if(a.length==b.length)
{
return a.localeCompare(b);
}
else
{
return -1;
}
}
);
}


function SmartPromptList(arrList, objInputId)
{
var objouter = document.getElementById( "__SmartDiv "); //Div
var objInput = document.getElementById(objInputId); //TextBox
var selectedIndex = -1;
var intTmp; //Temp variant to do loop...

if (objInput==null)
{
return;
}

//textbox lost focus
objInput.onblur =
function()
{
if(IsInRect() == false)
{
objouter.style.display = 'none ';
}
};
//Div lost focus
objouter.onblur =
function()
{
if(IsInRect() == false)
{
objouter.style.display = 'none ';
}
};

function IsInRect()
{
intRectX_Min = objouter.offsetLeft;
intRectX_Max = objouter.offsetLeft + objInput.clientWidth;
intRectY_Min = objInput.offsetTop;
intRectY_Max = objInput.offsetTop + objInput.clientHeight + 300;

if(
intMouseX > = intRectX_Min &&
intMouseX <= intRectX_Max &&
intMouseY > = intRectY_Min &&
intMouseY <= intRectY_Max
)
{
return true;
}
else
{
return false;
}
}

//Key in some text in textbox
objInput.onkeyup = checkKeyCode;
//TextBox gets focus
objInput.onfocus = checkAndShow;

function checkKeyCode()
{
var ie = (document.all)? true:false;
if (ie)
{
var keyCode = event.keyCode;

if (keyCode==40||keyCode==38)
{
//[Up] or [Down]
var isUp = false;
if(keyCode==40) <