首页 技术 正文
技术 2022年11月7日
0 收藏 400 点赞 937 浏览 3410 个字

1、传值:index下标传值、页面navigator传值

1、index下标
实现方式是:data-index="{{index}}"挖坑及e.currentTarget.dataset.index来填坑即可2、<navigator>标签
<navigator url="../enlist/enlist?unitPrice={{common.act_fee}}&is_home=0&a_id={{common.a_id}}">
或者
<view class="container" data-index="{{index}}" bindtap="edit"><image src="../../../images/icon_edit.png" /><text>编辑</text></view>
edit: function (e) {
var that = this;
// 取得下标
wx.navigateTo({
url: '../add/add?objectId='+objectId
});
},

2、取值:form表单取值、input框绑定取值

1、 form表单取值
1.1 方式一,通过<form bindsubmit="formSubmit">与<button formType="submit">标签配合使用
formSubmit: function(e) {
// detail
var detail = e.detail.value.detail;
// realname
var realname = e.detail.value.realname;
// mobile
var mobile = e.detail.value.mobile;
}2、方式二,通过<input bindblur="realnameConfirm">实现:失去焦点bindblur、数值变化bindchange等方法
realnameConfirm: function(e) {
var that = this;
that.setData({
realname:e.detail.value
})
}//然后可以在页面其他地方用到了,改校验的校验,改发送给后台的发送,等等

微信小程序:input输入框和form表单几种传值和取值方式

微信小程序输入框input

属性名 类型 默认值 说明
value String   输入框的内容
type String text input的类型,有效值:text,number,idcard,digit,time,date
password Boolean false 是否是密码类型
placeholder String   输入框为空时占位符
placeholder-style String   指定placeholder的样式
placeholder-class String input-placeholder 指定placeholder的样式类
disabled Boolean false 是否禁用
maxlength Number 140 最大输入长度,设置为0的时候不限制最大长度
auto-focus Boolean false 自动聚焦,拉起键盘。页面中只能有一个input设置auto-focus属性
focus Boolean false 使得input获取焦点
bindchange EventHandle   输入框失去焦点时,触发bindchange事件,event.detail={value:value}
bindinput EventHandle   除了date/time类型外的输入框,当键盘输入时,触发input事件,event.detail={value:value},处理函数可以直接return一个字符串,将替换输入框的内容。
bindfocus EventHandle   输入框聚焦时触发,event.detail = {value:value}
bindblur EventHandle   输入框失去焦点时触发,event.detail = {value:value}

示例代码:?

1234567891011121314151617181920212223242526272829303132333435363738394041 <!--input.wxml--><view class="section"> <input placeholder="这是一个可以自动聚焦的input" auto-focus/></view><view class="section"> <input placeholder="这个只有在按钮点击的时候才聚焦" focus="{{focus}}" /> <view class="btn-area"> <button bindtap="bindButtonTap">使得输入框获取焦点</button> </view></view><view class="section"> <input maxlength="10" placeholder="最大输入长度10" /></view><view class="section"> <view class="section__title">你输入的是:{{inputValue}}</view> <input bindinput="bindKeyInput" placeholder="输入同步到view中"/></view><view class="section"> <input bindinput="bindReplaceInput" placeholder="连续的两个1会变成2" /></view><view class="section"> <input bindinput="bindHideKeyboard" placeholder="输入123自动收起键盘" /></view><view class="section"> <input type="emoji" placeholder="这是一个带有表情的输入框" /></view><view class="section"> <input password type="number" /></view><view class="section"> <input password type="text" /></view><view class="section"> <input type="digit" placeholder="带小数点的数字键盘"/></view><view class="section"> <input type="idcard" placeholder="身份证输入键盘" /></view><view class="section"> <input placeholder-style="color:red" placeholder="占位符字体是红色的" /></view>

?

123456789101112131415161718192021222324252627282930313233343536373839404142 //input.jsPage({ 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(); } }})
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,116
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,588
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,433
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,204
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,840
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,925