<html> <head> <!----> <style> .my_list {color: #000000; background-color: #FFF00; font-size: 14px; border-style: solid; border-width: 2px; border-color:#000000;} .header { font-weight:bold; font-color: #004488; font-size: 16px;} .explain { font-color: #000000; font-size: 12px; } </style> <script> function ex_init() { document.getElementById("mylist").onkeypress=getKey; } </script></head> <body> <script> var FOCUS=0; /* default not focused */ var TYPED=""; /* default nothing typed */ function findMatch() { var found=-1; /* -1 means not found */ for(var i=0;found==-1&&i<document.f1.s1.length;i++) { var _str=""; _str=document.f1.s1[i].text.toUpperCase(); if(_str.indexOf(TYPED.toUpperCase())!=-1) found=i; } if(found!=-1) { document.f1.s1.selectedIndex=found; } return false; } function setFocus(_i) { FOCUS=_i; TYPED=""; document.f1.t2.value=TYPED; } function getKey(e) { var next; var ieKey,nsKey; if(e) { nsKey=String.fromCharCode(e.which); next=nsKey; } else { ieKey=event.keyCode; next=String.fromCharCode(ieKey); } TYPED+=next; TYPED=TYPED.toUpperCase(); document.f1.t2.value=TYPED; return findMatch(); } </script> <form name=f1 ID=Form1> <table align=center> <tr><td colspan=2 align=center class=header>Select List - Determine Typed Selection</td></tr> <tr><td>Click to focus -></td> <td> <select class=my_list id="mylist" name=s1 onfocus="setFocus(1)" onblur="setFocus(0)"> <option value=1>1</option> <option value=2>2</option> <option value=3>3</option> <option value=4>4</option> <option value=5>5</option> <option value=6>6</option> <option value=7>7</option> <option value=8>8</option> <option value=9>9</option> <option value=10>10</option> </select> </td></tr> <tr><td>Characters Typed:</td><td><input type=text name=t2 value="" ID=Text1></td></tr> <tr><td colspan=2> </td></tr> <tr><td colspan=2 class=explain>Only when the select list has focus on it will it detect characters typed. As the characters are typed, the first matched item in the select list is automatically selected for you.<BR><BR>You can hide the Characters Typed item: it is shown here only to help you understand how this works.</td></tr> </table> </form> <BR> </body> </html>
<option value=1>1
<option value=2>2
<option value=3>3
<option value=4>4
<option value=5>5
</select>
<head>
<!---->
<style>
.my_list {color: #000000; background-color: #FFF00; font-size: 14px; border-style: solid; border-width: 2px; border-color:#000000;}
.header { font-weight:bold; font-color: #004488; font-size: 16px;}
.explain { font-color: #000000; font-size: 12px; }
</style>
<script>
function ex_init()
{
document.getElementById("mylist").onkeypress=getKey;
}
</script></head>
<body>
<script>
var FOCUS=0; /* default not focused */
var TYPED=""; /* default nothing typed */
function findMatch()
{
var found=-1; /* -1 means not found */
for(var i=0;found==-1&&i<document.f1.s1.length;i++)
{
var _str="";
_str=document.f1.s1[i].text.toUpperCase();
if(_str.indexOf(TYPED.toUpperCase())!=-1)
found=i;
}
if(found!=-1)
{
document.f1.s1.selectedIndex=found;
}
return false;
}
function setFocus(_i)
{
FOCUS=_i;
TYPED="";
document.f1.t2.value=TYPED;
}
function getKey(e)
{
var next;
var ieKey,nsKey;
if(e)
{
nsKey=String.fromCharCode(e.which);
next=nsKey;
}
else
{
ieKey=event.keyCode;
next=String.fromCharCode(ieKey);
}
TYPED+=next;
TYPED=TYPED.toUpperCase();
document.f1.t2.value=TYPED;
return findMatch();
}
</script>
<form name=f1 ID=Form1>
<table align=center>
<tr><td colspan=2 align=center class=header>Select List - Determine Typed Selection</td></tr>
<tr><td>Click to focus -></td>
<td>
<select class=my_list id="mylist" name=s1 onfocus="setFocus(1)" onblur="setFocus(0)">
<option value=1>1</option>
<option value=2>2</option>
<option value=3>3</option>
<option value=4>4</option>
<option value=5>5</option>
<option value=6>6</option>
<option value=7>7</option>
<option value=8>8</option>
<option value=9>9</option>
<option value=10>10</option>
</select>
</td></tr>
<tr><td>Characters Typed:</td><td><input type=text name=t2 value="" ID=Text1></td></tr>
<tr><td colspan=2> </td></tr>
<tr><td colspan=2 class=explain>Only when the select list has focus on it will it detect characters typed. As the characters are typed, the first matched item in the select list is automatically selected for you.<BR><BR>You can hide the Characters Typed item: it is shown here only to help you understand how this works.</td></tr>
</table>
</form>
<BR>
</body>
</html>
我把以前一个时间判断星期几的方法应用到这里来,:)
<select name=select1 onkeydown="show(this)">
<option value="0">00000</option>
<option value="1">11111</option>
<option value="2">22222</option>
<option value="3">33333</option>
<option value="4">44444</option>
<option value="5">55555</option>
<option value="6">66666</option>
<option value="7">77777</option>
<option value="8">88888</option>
<option value="9">99999</option>
</select>
<script language=javascript>
function show(obj)
{
if((event.keyCode>47)&&(event.keyCode<58))
obj.selectedIndex="0123456789".charAt(event.keyCode-parseInt(48));
if((event.keyCode>95)&&(event.keyCode<106))
obj.selectedIndex="0123456789".charAt(event.keyCode-parseInt(96));
}
</script>
<option value=1>1
<option value=2>2
<option value=3>3
<option value=4>4
<option value=5>5
<option value=6>6
<option value=7>7
<option value=8>8
<option value=9>9
<option value=10>10
</select>
好象没必要加obj.selectedIndex="0123456789".charAt
这段代码有什么特别的意义吗