function changeAll()
{
var sele=document.getElementById("select"); //这是一个下拉列表,从数据库读取的数据
var sel=document.getElementById("sel").value; //用来输入的文本框
var ceshi=document.getElementById("ceshi"); //测试用文本框
var a=new Array(); //定义的数组,用来存放下拉列表里面的数据
for(i=0;i<=sele.length-1;i++)
{
a[i]=sele.options(i).value;
}
for(j=0;j<=a.length;j++)
{
if(sel.indexOf(a[j])<0)
{
sele.value=a[j];
ceshi.value=a[j];
}
}
}当在文本框中输入某个字符,在下拉列表中自动指定含有这个字符的某条数据。
问题是显示出来下拉列表是没数据的,测试用文本框显示undefined。
单独把sele.value=a[j]中的j换成数字就有数据了,菜鸟求解答
{
var sele=document.getElementById("select"); //这是一个下拉列表,从数据库读取的数据
var sel=document.getElementById("sel").value; //用来输入的文本框
var ceshi=document.getElementById("ceshi"); //测试用文本框
var a=new Array(); //定义的数组,用来存放下拉列表里面的数据
for(i=0;i<=sele.length-1;i++)
{
a[i]=sele.options(i).value;
}
for(j=0;j<=a.length;j++)
{
if(sel.indexOf(a[j])<0)
{
sele.value=a[j];
ceshi.value=a[j];
}
}
}当在文本框中输入某个字符,在下拉列表中自动指定含有这个字符的某条数据。
问题是显示出来下拉列表是没数据的,测试用文本框显示undefined。
单独把sele.value=a[j]中的j换成数字就有数据了,菜鸟求解答
<head>
<title>无标题页</title> <script type="text/javascript">
function changeAll()
{
var sele=document.getElementById("select"); //这是一个下拉列表,从数据库读取的数据
var sel=document.getElementById("sel").value; //用来输入的文本框
var ceshi=document.getElementById("ceshi"); //测试用文本框
//var a=new Array(); //定义的数组,用来存放下拉列表里面的数据
var a="";
for(i=0;i<=sele.length-1;i++)
{
a=sele[i].text;
if(a.indexOf(sel)!=-1)
{
sele.selectedIndex=i;
ceshi.value=sele[i].value;
break;
}
//a[i]=sele.options(i).value;
}
// for(j=0;j<=a.length;j++)
// {
// if(sel.indexOf(a[j])<0)
// {
// sele.value=a[j];
// ceshi.value=a[j];
// }
// }
}
window.onload=function(){
document.getElementById("Search").onclick=function(){
changeAll();
}
}
</script>
</head>
<body>
<select id="select">
<option value="1">数据一</option>
<option value="2">数据二</option>
<option value="3">数据三</option>
<option value="4">数据四</option>
</select>
<input type="text" id="sel" />
<input type="text" id="ceshi" />
<input type="button" value="Search" id="Search" />
</body>
</html>
{
if (sel.indexOf(a[j]) < 0) //这里应该是>0 <0是没有找到a[j] >0才是找到了
{
sele.value = a[j];
ceshi.value = a[j];
}
}
{
sele.value=a[j];
ceshi.value=a[j];
}
兄弟的循环学的不扎实啊,条件满足,怎么能不返回呢?
if(sel.indexOf(a[j])<0)
{
sele.value=a[j];
ceshi.value=a[j];
return;
}