如何将jsp中<input>设为只读

将一个input变为只读,可以使用 readonly 属性 和 disabled 属性。 
用disabled 属性时,文字显示为灰色。 
下面的两种方法都是可以的: 
Java代码  收藏代码
  1. <input id ="" name=""  readonly   />  
  2. <input id ="" name=""  disabled />  

但是,使用 disabled 时,表单提交后,在后台将不会取到值了。 

如果想得到值.就用javascript来拼值。如: 
Java代码  收藏代码
  1. <script>  
  2. function onc(){  
  3. var valuemes=document.form[0].mes.value;  
  4. document.form[0].invalue=valuemes;  
  5. documnet.form[0].submit();  
  6. }  
  7. </script>  
  8.   
  9. <form action="test">  
  10. <input type="hidden" name="invalue">  
  11. <input type="text" value="你好" name="mes" disabled="disabled">  
  12. <input type="button" value="提交" onclick="onc()">  
  13. </form>  


建议用 readonly 


注:有时候设置某个input 是否提交,可以在js中这样写: 
Java代码  收藏代码
  1. //设置可用  
  2. document.getElementById("xxx").disabled="disabled";  
  3. //设置不可用  
  4. document.getElementById("xxx").enabled;  
【转载自】http://lixh1986.iteye.com/blog/1746928
原文地址:https://www.cnblogs.com/rookiebob/p/3749394.html