readonly 屬性規(guī)定輸入字段為只讀
一般用法
<input readeonly />
<input readonly="readonly"/>
其實(shí)只要 當(dāng)前表單元素上面有readony 屬性就行無論他的值是什么
//以下兩種均有效
<input readonly="false"/>
<input readonly=""/>
設(shè)置為存在readonly屬性的元素,只是不能編輯。仍然可以使用 tab 鍵切換到該字段,還可以選中或拷貝其文本。
只要有 html 元素中有了 readonly 屬性,$0.readonly=true
只有刪掉readonly屬性($0.readonly=undefined)或者$0.readonly=fasle(此時(shí)element 中也看不到該html 有readonly 屬性)
disabled 屬性規(guī)定應(yīng)該禁用 input 元素
用法
<input disabled />
<input disabed="disabled"/>
不能修改,不能使用 tab 鍵切換到該字段,不可以選中或拷貝其文本。其上綁定的事件也均不能被觸發(fā)。
react jsx 語法中 可以設(shè)置
<input readOnly={true} />
<input readOnly={1} />
<input readOnly={readonly} />
<input readOnly/>
vue 中
<div id="example">
<input v-bind:readonly="isReadOnly">
</div>
var vm = new Vue({
el: '#example',
data: {
editable: false
},
computed: {
// a computed getter
isReadOnly: function () {
return this.editable? null:"readonly"
}
}
})