日期:2014-05-17  浏览次数:20744 次

即时查询的问题,帮忙看看 100分
实现输入框即时查询显示在select 代码如下 原帖地址 100分

出的错误 进不去200状态 请求的文件出错,请检查

Java JavaScript jsp实现


http://topic.csdn.net/u/20120709/16/9bcaa864-b8c3-475e-aa62-c7366c331ff8.html?seed=1689828436&r=79072980#r_79072980


form里面:


<tr class="tr_data1">
  <td>公司名称</td>
  <td><select name="companyName" size="1" style="position:absolute; left: 237px; top: 85px; width: 220px; height: 20px;
  clip: rect(0 237 18 200)" onchange="changeValue();" onclick="checkValue();" >
  <%
  for(Iterator iter = list.iterator(); iter.hasNext(); ) {
  piv = (PropertyInfoView)iter.next();
  %>
  <option value="<%=piv.getId() %>"><%=piv.getCompanyName() %></option>
  <%
  }  
  %>
  </select><input type="text" size="35" id="company_name" name="company_name" style="position:absolute; left: 237px;  
  top: 85px; width: 220px; height: 18px" onclick="checkInputValue();" onkeyup="getD(this.value);"></td>
  <div id="dvContent" style="display:none;position:absolute"></div>
  
</tr>
------------------------
javascript:

//下拉  
var obj;;
var to;//setTimeout时间变量,对于输入快时可以延迟查询
function getD(va)
{
if(to) clearTimeout(to);
to = setTimeout("getData('"+va+"')",500);//延迟500毫秒后再查询
}
function getData(va)
{
document.getElementById("dvContent").style.display="none";
if(va!="")
{
var url='res.jsp?ts='+new Date().getTime()+'&k='+va;
obj = CreateAJAX();
if(obj)
{
obj.onreadystatechange=handlejs;
obj.open('GET',url,true);
obj.send(null);
}
else
alert("创建AJAX对象失败!");
}
}
function handlejs()
{
if(obj.readyState==4)
{
if(obj.status==200)
{  
if(obj.responseXML)
{
xml=obj.responseXML;
node=xml.getElementsByTagName("d");
var dv=document.getElementById("dvContent");
dv.innerHTML=node[0].firstChild.nodeValue;
dv.style.display="";
}
}
else  
alert("请求的文件出错,请检查!");  
}  
}
function CreateAJAX()
{  
if(window.XMLHttpRequest) {
return new XMLHttpRequest();
} else if (window.ActiveXObject) {
return new ActiveXObject("Microsoft.XMLHTTP");
}
}
function setContent(data)
{
document.getElementById('company_name').value=data;
document.getElementById('dvContent').style.display="none";
}
function setPosition()
{
var dv=document.getElementById('dvContent');
dv.style.left=getPos("x");
dv.style.top=getPos("y")+20;
}
function getPos(type)
{
var p;
var o=document.getElementById('company_name');
if(type=="x")
p=o.offsetLeft;
else
p=o.offsetTop;
while(o=o.offsetParent)
{
if (type=="x")
{
p+=o.offsetLeft;  
}
else
{
p+=o.offsetTop;
}
}
return p;
}
   


------------------------
jsp:

<%@ page language="java" import=" java.util.*" %>
<jsp:directive.page import="com.pkpm.fund.bean.PropertyInfoBean"/>
<jsp:directive.page import="com.pkpm.fund.view.PropertyInfoView"/>
<%  
String k,xml,res;
res = "";
xml =