用disabled 屬性時,文字顯示爲灰色。
下面的兩種方法都是可以的:
- <input id ="" name="" readonly />
- <input id ="" name="" disabled />
但是,使用 disabled 時,表單提交後,在後臺將不會取到值了。
如果想得到值.就用javascript來拼值。如:
- <script>
- function onc(){
- var valuemes=document.form[0].mes.value;
- document.form[0].invalue=valuemes;
- documnet.form[0].submit();
- }
- </script>
- <form action="test">
- <input type="hidden" name="invalue">
- <input type="text" value="你好" name="mes" disabled="disabled">
- <input type="button" value="提交" οnclick="onc()">
- </form>
建議用 readonly
注:有時候設置某個input 是否提交,可以在js中這樣寫:
- //設置可用
- document.getElementById("xxx").disabled="disabled";
- //設置不可用
- document.getElementById("xxx").enabled;