您现在的位置:首页 >> 前端 >> 内容

input和select设置为不可修改及取消不可修改

时间:2017/8/9 8:59:36 点击:

  核心提示:input和select设置为不可修改及取消不可修改。1、当需设置input和select显示为只读(不可修改)时,两者有不同的设置方法。1)input可设置为只读,在其中增加属性readonly=r...

input和select设置为不可修改及取消不可修改。

1、当需设置input和select显示为只读(不可修改)时,两者有不同的设置方法。

1)input可设置为只读,在其中增加属性readonly=“readonly”;

2)select没有readonly这个属性,不过可以通过disabled=“disabled”进行设置;

3)其中input设置为只读时,仍可提交,而select设置为不可用时,则不可提交。此时可在提交函数中,通过jQuery单独获取select的值,然后提交。

2、上述只读(不可修改)的设置与取消

1)设置 可直接在input或select标签中增加对应的属性;

可通过jQuery进行设置,如:$("#id").attr("readonly",readonly);——其中id为input标签的id $("#id").attr("disabled",disabled);——其中id为select标签的id

2)取消 可通过jQuery进行取消,如:$("#id").removeAttr("readonly");——其中id为input标签的id $("#id").removeAttr("disabled");——其中id为select标签的id

Tags:IN NP PU UT 
作者:网络 来源:zhaoyizhil