将一個input變為隻讀,可以使用 readonly 屬性 和 disabled 屬性。
用disabled 屬性時,文字顯示為灰色。
下面的兩種方法都是可以的:
<input id ="" name="" readonly />
<input id ="" name="" disabled />
[color=red]但是,使用 disabled 時,表單送出後,在背景将不會取到值了。[/color]
如果想得到值.就用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="送出" onclick="onc()">
</form>
[b][color=red]建議用 readonly[/color] [/b]
[b]注:[/b]有時候設定某個input 是否送出,可以在js中這樣寫:
//設定可用
document.getElementById("xxx").disabled="disabled";
//設定不可用
document.getElementById("xxx").enabled;
引用:
[url]http://bbs.csdn.net/topics/380063466[/url]
-
轉載請注明
原文出處: http://lixh1986.iteye.com/blog/1746928
-
-