http://www1.color8th.com/Content/MyOnly.aspx?Id=165557
2006年9月4日
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>多级关联菜单数据库版</title>
<!–
数据库:test.mdb
表:dbselect
表结构:id(自增) school(文本) department(文本) grade(文本) student(文本)
IE6,NS7,Mozilla下测试通过
–>
</head>
<body>
<form name="frm">
<select name=school onchange="MulSelect(1)"></select>
<select name=department onchange="MulSelect(2)"></select>
<select name=grade onchange="MulSelect(3)"></select>
<select name=student></select>
</form>
<script>
var arrSel=["school","department","grade","student"]
arrData=[];
<%
dim conn,rs
set conn = Server.CreateObject("ADODB.Connection")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.mappath("test.mdb") & ";Persist Security Info=False"
set rs=conn.execute("select * from dbselect")
do while not rs.eof
%>
arrData[arrData.length]=["<%=trim(rs("school"))%>","<%=trim(rs("department"))%>","<%=trim(rs("grade"))%>","<%=trim(rs("student"))%>"]
<%
rs.movenext
loop
rs.close:set rs=nothing
conn.close:set conn=nothing
%>
</script>
<script>
function MulSelect(num){
var find=false
var i,j,arrTemp=[];
for(i=0;i<num;i++)arrTemp[i]=eval("document.frm."+arrSel[i]).value
if(num<arrSel.length)
with(eval("document.frm."+arrSel[num])){
length=0
for(i=0;i<arrData.length;i++){
for(j=0;j<num;j++)if(arrTemp[j]!=arrData[i][j])break;
if(j!=num)continue;
if(length==0 ¦ ¦options[length-1].text!=arrData[i][num]){
for(m=0;m<options.length;m++)if(options[m].text==arrData[i][num])find=true
if(!find)options[options.length]=new Option(arrData[i][num],arrData[i][num])
}
}
MulSelect((num+1))
}
}
MulSelect(0)
</script>
</body>
</html>
<html>
<head>
<title>可以编辑的下拉列表 – by WildWind<wildwind_zz@21cn.com>…</title>
<script language="JavaScript">
<!–
function catch_keydown(sel)
{
switch(event.keyCode)
{
case 13:
//Enter;
sel.options[sel.length] = new Option("","",false,true);
event.returnValue = false;
break;
case 27:
//Esc;
alert("text:" + sel.options[sel.selectedIndex].text + ", value:" + sel.options[sel.selectedIndex].value +
";");
event.returnValue = false;
break;
case 46:
//Delete;
if(confirm("删除当前选项!?"))
{
sel.options[sel.selectedIndex] = null;
if(sel.length>0)
{
sel.options[0].selected = true;
}
}
event.returnValue = false;
break;
case 8:
//Back Space;
var s = sel.options[sel.selectedIndex].text;
sel.options[sel.selectedIndex].text = s.substr(0,s.length-1);
event.returnValue = false;
break;
}
}
function catch_press(sel)
{
sel.options[sel.selectedIndex].text = sel.options[sel.selectedIndex].text + String.fromCharCode
(event.keyCode);
event.returnValue = false;
}
//–>
</script>
</head>
<body onload="s1.focus();">
<h3>操作方法:</h3>
<p>ƒ.按Enter键开始添加输入新的选项…<br>„.按Del键删除当前选项…<br>….按Esc键查看当前选项的text和value
值…<br>†.按BackSpace键删除当前选项的前一个字符…<br>
</p>
<h3>测试结果:</h3>
<p>ƒ.IE6.0测试通过…<br>
</p>
<br>
<h3>建议&意见:</h3>
<p>ƒ.大家可以做成htc,将这些函数绑在css上(很简单,不再介绍…)…<br>
</p>
<h3>示例:</h3>
<p>
<select name=s1 onkeydown="catch_keydown(this);" onkeypress="catch_press(this);" style="font-
size:12px;"><option>—</option></select>
</p>
</body>
</html>
<h1>限制文本框中字符的输入[JavaScript]</h1>
<P><FONT face=Verdana>只能输入汉字<br/><INPUT onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\u4E00-\u9FA5]/g,''))" onkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g,'')"></FONT></P>
<P><FONT face=Verdana></FONT> </P>
<P><FONT face=Verdana>只能输入全角<br/><INPUT onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\uFF00-\uFFFF]/g,''))" onkeyup="value=value.replace(/[^\uFF00-\uFFFF]/g,'')"></FONT></P><FONT face=Verdana>
<P><br/>只能输入数字<br/><INPUT onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))" onkeyup="value=value.replace(/[^\d]/g,'') "></P>
<P><br/>只能输入英文和数字<br/><INPUT onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))" onkeyup="value=value.replace(/[\W]/g,'') "></FONT></P>