本文編輯: 技術陽光群星瀏覽 7223
版權所有,嚴禁轉載
textarea 多行輸入框。
屬性效果圖:
代碼:
wxml
<view class="content">
placeholder:
<textarea placeholder="占位符" />
<textarea placeholder="占位符 改變樣式style" placeholder-style=
"color:blue"/>
<textarea placeholder="占位符 改變樣式class" placeholder-class="placeholdText"/>
</view>
wxss
.content{
border:1px black solid;
margin: 10px;
font-size: 10pt;
padding: 10px;
}
textarea{
border: 1px red solid;
margin: auto;
width:100%;
height: 3em;
margin-top:5px;
padding: 3px;
}
/*占位符樣式*/
.placeholdText{
font-size: 2em;
}
事件效果圖:
wxml:
<view class="content">
auto-height:
<textarea auto-height placeholder="自動增高,style.height不生效"/>
bindinput="當內容改變"
<textarea placeholder="" bindlinechange="bindlinechange"/>
bindfocus:當獲取焦點
<textarea placeholder="當獲取焦點" value="" bindfocus="bindfocus"/>
bindblur:當失去焦點觸發
<textarea placeholder="當失去焦點" bindblur="bindblur"/>
</view>
事件觸發:
<view class="content" style="color:blue">
{{log}}
</view>
js:
Page({
data:{
log:'事件觸發'
},
//行高改變時
bindlinechange:function(e){
var height=e.detail.height;
var heightRpx=e.detail.heightRpx;
var lineCount=e.detail.lineCount;
this.setData({
log:"height="+height+" | heightRpx="+heightRpx+" | lineCount="+lineCount
})
},
//文本失去焦點
bindblur:function(e){
var value=e.detail.value;
this.setData({
log:"bindblur失去改變.獲取textarea值="+value
})
},
//文本獲取焦點
bindfocus:function(e){
var value=e.detail.value;
this.setData({
log:"bindfocus獲取焦點,獲取textarea值="+value
})
}
})
wxss:
.content{
border:1px black solid;
margin: 10px;
font-size: 10pt;
padding: 10px;
}
textarea{
border: 1px red solid;
margin: auto;
width:100%;
height: 3em;
margin-top:5px;
padding: 3px;
}
屬性 | 描述 | 類型 | 默認值 |
---|---|---|---|
value | 初始內容 | String | |
placeholder | 占位符 | String | |
placeholder-style | 指定 placeholder 的樣式 | String | |
placeholder-class | 指定 placeholder 的樣式類 | String | textarea-placeholder |
disabled | 是否禁用 | Boolean | false |
maxlength | 最大輸入長度,設置為 0 的時候不限制最大長度 | Number | 140 |
auto-focus | 自動聚焦,拉起鍵盤。頁面中只能有一個 input 或 textarea標簽時, 設置 auto-focus 屬性 | Boolean | false |
focus | 獲取焦點(當前開發工具暫不支持) | Boolean | false |
auto-height | 是否自動增高,設置auto-height時,style.height不生效 | Boolean | false |
bindfocus | 輸入框聚焦時觸發event.detail = {value: value} | EventHandle | |
bindblur | 輸入框失去焦點時觸發event.detail = {value: value} | EventHandle | |
bindlinechange | 輸入框行數變化時調用event.detail = {height: 0, heightRpx: 0, lineCount: 0} | EventHandle |
wxml
<!--=======屬性=======-->
<!--value:輸入框內容-->
<textarea value="內容"/>
<!--placeholder:占位符,對輸入框內容提示-->
<textarea placeholder="占位符" placeholder-class="占位符靜態樣式" placeholder-style="占位符動態樣式"/>
<!--disabled:控制標簽有效,或者失效狀態,在失效狀態,不能獲取該值-->
<textarea disabled="true"/>
<textarea disabled/> 等同于 <textarea disabled="false"/>
<!--maxlength:內容長度限制,默認140-->
<textarea maxlength="100"/>
<textarea maxlength/> 等同于 <textarea maxlength="140"/>
<!--focus:初始化時,獲取輸入焦點(目前開發工具暫不支持)-->
<textarea focus="true"/>
<textarea focus/> 等同于 <textarea focus="false"/>
<!--auto-focus:當界面只有一個textarea,自動獲取焦點-->
<textarea auto-focus="true"/>
<textarea auto-focus/> 等同于 <textarea auto-focus="false"/>
<!--auto-height:是否自動增高,設置auto-height時,style.height不生效-->
<textarea auto-height="true"/>
<textarea auto-height/> 等同于 <textarea auto-height="false"/>
<!--=======事件=======-->
<!--bindlinechange:輸入框行數變化時調用 返回參數:height,heightRpx,lineCount-->
<textarea bindlinechange="自己定義函數名"/>
<!--bindfocus:當獲取焦點,可用輸入狀態時觸發-->
<textarea bindfocus="自己定義函數名"/>
<!--bindblur:當失去焦點觸發-->
<textarea bindblur="自己定義函數名"/>