This article mainly introduces jquery's method of supporting the selection of "enter" or "focus" by extending the select control. It analyzes the implementation skills of jQuery extension by adding the "enter" and "focus" functions for the select space, for more information, see the example in this article. We will share this with you for your reference. The details are as follows:
/**************************************** @ author jdkleo* @ date 2013/2/27 JQuery SelKeysUSAGE: 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){ var flag = 1; var open = 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); var code = e.keyCode || e.which || e.charCode; if(code == 13) { open(); return false; } }); sel.blur(function(){ sel.get(0).size=1; flag=1; }); } /**---------focus---------**/ this.focus = function(sel){ var flag = 1; var open = 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(); return false; }); sel.blur(function(){ sel.get(0).size=1; flag=1; }); sel.keydown(function(e){ e = e ? e :(window.event ? window.event : null); var code = e.keyCode || e.which || e.charCode; if(code == 13) { sel.get(0).size=1; flag=1; return false; } }); } /**---------all---------**/ jQuery.selkeys = this; return jQuery; })(jQuery);
I hope this article will help you with jQuery programming.