禁用select下拉选的小方法
? 今天看到一大神处理下select下拉选的一段代码,在次做个笔记。这段代码主要用于禁用select标签,让其选中的值不能被改变。好了,不瞎扯了,看代码吧。
?
$(function(){//方法1:参考大神的代码 $("#statusprice").focus(function(){ this.si=this.selectedIndex; }); $("#statusprice").change(function(){ this.selectedIndex=this.si; });//方法2:比较通俗的方法,直接禁用select标签,让其至灰 $("#statusprice").attr("disabled",true); });?该代码运行后的结果是:让select一直保持选中“已定价”状态,不能选中其他选项。
?