webdn
 
  首页     免费截图     VIP会员区     广告Banner     技术文档     网站模板  
网站截图,网站每日新 !
买域名送空间
虚拟主机 域名注册

首页 >> WebDN 文档 >> 网络编程 >> ASP.net 技术资料 >> Page 25 >> ASP.NET 中 DropDownList 输入问题的最简单解决方案

 

ASP.NET 中 DropDownList 输入问题的最简单解决方案

【摘 要】 然后在你的程序中拖拽一个 DropDownList 控件,在到HTML页中找到这个 控件的代码,在他后面加上 onkeydown="catch_keydown(this);" onkeypress="catch_press(this);",运行程序就好了

先把这段JS代码放到你页面的HTML中去

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;

 }

然后在你的程序中拖拽一个  DropDownList 控件,在到HTML页中找到这个 控件的 代码

在他后面加上  onkeydown="catch_keydown(this);" onkeypress="catch_press(this);"

运行程序就好了



电话咨询:010-60520722 QQ咨询:3792656   |   583696287   |   66733350 关于WebDN  |  站点地图  |  联系我们  |  支付方式  |  友情链接
© 2004-2008 WebDN.com 版权所有. 沪ICP备05040479号