jquery通过扩展select控件实现支持enter或focus选择的方法
本文实例讲述了jquery通过扩展select控件实现支持enter或focus选择的方法。分享给大家供大家参考,具体如下:
/*************************************** *@authorjdkleo *@date2013/2/27 JQuerySelKeys USAGE: jQuery.selkeys.enter(jQuery("#selcon")); jQuery.selkeys.focus(jQuery("#selcon2")); *****************************************/ (function(jQuery){ this.version='(beta)(0.0.1)'; this.all={}; /**---------enter---------**/ this.enter=function(sel){ varflag=1; varopen=function(){ if(flag==1){ sel.get(0).size=sel.get(0).options.length; flag=0; }else{ sel.get(0).size=1; flag=1; } }; sel.keydown(function(e){ e=e?e:(window.event?window.event:null); varcode=e.keyCode||e.which||e.charCode; if(code==13) { open(); returnfalse; } }); sel.blur(function(){ sel.get(0).size=1; flag=1; }); } /**---------focus---------**/ this.focus=function(sel){ varflag=1; varopen=function(){ if(flag==1){ sel.get(0).size=sel.get(0).options.length; flag=0; }else{ sel.get(0).size=1; flag=1; } }; sel.focus(function(){ open(); returnfalse; }); sel.blur(function(){ sel.get(0).size=1; flag=1; }); sel.keydown(function(e){ e=e?e:(window.event?window.event:null); varcode=e.keyCode||e.which||e.charCode; if(code==13) { sel.get(0).size=1; flag=1; returnfalse; } }); } /**---------all---------**/ jQuery.selkeys=this; returnjQuery; })(jQuery);
希望本文所述对大家jQuery程序设计有所帮助。