WeChat applet input box detailed example code

高洛峰
Release: 2017-03-21 16:57:20
Original
4896 people have browsed it

This article mainly introduces the detailed explanation and simple examples of the input box of the WeChat applet. Friends in need can refer to the

implementation renderings:

WeChat applet input box detailed example code

WeChat applet input box input

##placeholder-Stringinput-placeholderSpecify the style class of placeholderdisabledBooleanfalseWhether to disablemaxlengthNumber140Maximum input length , when set to 0, there is no limit to the maximum length auto-focusBooleanfalseAuto focus, pull up keyboard. There can only be one input in the page that sets the auto-focus attributefocusBooleanfalseso that the input gets focusbindchangeEventHandleWhen the input box loses focus, the bindchange event is triggered, event.detail={value:value} bindinputEventHandleInput boxes other than date/time types trigger input events when keyboard input is made , event.detail={value:value}, the processing bindfocusEventHandleTriggered when the input box is focused, event.detail = {value:value}bindblurEventHandleTriggered when the input box loses focus, event.detail = {value:value}
AttributeNameTypeDefault valueDescription
valueString Input The content of the box
typeStringtextType of input, valid values: text, number, idcard, digit ,time,date
passwordBooleanfalse Whether Is the password type
placeholderString Placeholder when the input box is empty
placeholder-styleString Specify the style of placeholder
class
function can directly return a string , which will replace the content of the input box.
Sample code:



 
 
 
 
 
 
 你输入的是:{{inputValue}}
 
 
 
 
 
 
 
 
 
Copy after login
//input.js
Page({
 data:{
 focus:false,
 inputValue:""
 },
 bindButtonTap:function(){
 this.setData({
 focus:Date.now()
 })
 },
 bindKeyInput:function(e){
 this.setData({
 inputValue:e.detail.value
 })
 },
 bindReplaceInput:function(e){
 var value = e.detail.value;
 var pos = e.detail.cursor;
 if(pos != -1){
 //光标在中间
 var left = e.detail.value.slice(0,pos);
 //计算光标的位置
 pos = left.replace(/11/g,'2').length;
 }

 //直接返回对象,可以对输入进行过滤处理,同时可以控制光标的位置
 return {
 value:value.replace(/11/g,'2'),
 cursor:pos
 }

 //或者直接返回字符串,光标在最后边
 //return value.replace(/11/g,'2'),
 },
 bindHideKeyboard:function(e){
 if(e.detail.value === "123"){
 //收起键盘
 wx.hideKeyboard();
 }
 }
})
Copy after login
Thank you for reading, I hope it can help everyone, thank you for your support of this site!

The above is the detailed content of WeChat applet input box detailed example code. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!