function chgselectlist()
{
var txt = document.all.item("strtest").value // 输入文字
var txtlength = txt.length for(var i=0; i<document.all.item("comm").length; i++)
{
if(document.all.item("comm").options[i].text.substring(0, txtlength) == txt)
{
document.all.item("comm").options[i].selected = true
return
}
}}
{
var txt = document.all.item("strtest").value // 输入文字
var txtlength = txt.length for(var i=0; i<document.all.item("comm").length; i++)
{
if(document.all.item("comm").options[i].text.substring(0, txtlength) == txt)
{
document.all.item("comm").options[i].selected = true
return
}
}}
谢谢楼上,可是还是没有实现我要的效果,我是要根据input里的文字,来把select的文本里凡是含有input里字符串的选项都排在靠前的位置,好方便用户选择。奇遇不含有相应字符串的选项,则排在靠后的位置,
仍然要提供给用户选择的。
function chgselectlist()
{
var txt = document.all.item("strtest").value // 输入文字
var txtlength = txt.length;
obj = document.all.item("comm");
for(var i=0; i<obj.length; i++) {
if(obj.options[i].text.substr(0,txtlength) == txt) {
j = i;
while(j>1 && obj.options[j-1].text.substr(0,txtlength) != txt) {
obj.options[j].swapNode(obj.options[j-1]);
j--;
}
}
}
}
</script>
function chgselectlist()
{
var tmp=strtest.value,j=0
for(var i=0;i<comm.length;i++)
{
if(eval("comm["+i+"].text.search(/"+tmp+"/)!=-1"))
{
var j=0
comm[i].swapNode(comm[j])
j++
}
}
}
</script>
function chgselectlist()
{
var tmp=strtest.value,j=0
var j=0
for(var i=0;i<comm.length;i++)
{
if(eval("comm["+i+"].text.search(/"+tmp+"/)!=-1"))
{
comm[i].swapNode(comm[j])
j++
}
}
}
</script>