微信小程序

var id = e.target.id//根据点击不同的view获取对应的id值           

  var action = e.currentTarget.dataset.action
     
    console.log(action); //father
       
                     
var action = e.target.dataset.action;
         
   console.log(action); //undefined
 
方法e.currentTarget.dataset.action会获取有事件的那个元素,即view,所以获得“father”
<navigator url="">跳转页面</navigator>
this.setData    实时更新渲染界面   点击之后触发事件,执行函数,更新数据,。 

<view  data-id="{{1}}"  data-haha="{{index}}" bindtap="a"  id="aabb">点击获取data-id绑定的id值</view>

a:function(e){

     console.log(event)    //打印出view中所有属性的值,包括“点击获取data-id绑定的id值”

     console.log(event.currentTarget.dataset.id)    //打印出data-id绑定的id值

     console.log(event.currentTarget.dataset.haha)   //打印出index的值

     console.log(event.currentTarget.id)    //打印出aabb     

}

=====================================================================================

获取input 的值。发现两种方式。

1,通过form 方式 bindsubmit=" "

<form bindsubmit='getName'> 
<input  name="userName"/> 
<button form-type="submit"> 提交</button>
</form>
js
var val = e.detail.value.userName; 
console.log("user:" ,val)
 
2, 通过  bindinput=" "  
 
<input  name="userPhone"  value="{{phone}}"  bindinput="goDetail" />
js
 
this.setData({
userPhone: e.detail.value
})
我不能直接在这里consloe.log. 会报错不知道为何,但是值是确实能获取到
 
bindtap和catchtap的区别
bind事件绑定不会阻止冒泡事件向上冒泡,
catch事件绑定可以阻止冒泡事件向上冒泡。
 
 
 
 
不管前方的路有多苦,只要走的方向正确,不管多么崎岖不平,都比站在原地更接近幸福。 ——宫崎骏 《千与千寻》
原文地址:https://www.cnblogs.com/City-wall/p/10634887.html