jQuery中on方法绑定事件如何有效的获取当前点击元素的index下标

<ul class="accountlist">


  <li v-for="(item,index) in bankcardData" :key="index" @click="curindex === index" :class="curindex === index ? 'active' : ''">

    <i class="icon-corner corner" v-if="curindex === index"></i>

    <span class="textcenter">{{item.bankName}}</span>

    <p class="card-number textleft">{{item.accountNo}}</p>

    <div class="anchor">

      <button class="textleft btn default-btn" @click="activestyle($event,index)" :class="curindex === index?'opacity':''">设置默认</button>

      <button class="textright cancel-btn" v-popover:popover>解除绑定</button>

    </div>

  </li>

</ul>


setDefault(){

  var self = this;

  $('.accountlist').on('click', '.default-btn', function() {

    var curli = $(this).parents('li');

    $('.accountlist').prepend(curli);


    var curliIndex = curli.index();

    console.log(curliIndex); //curliIndex 当前下标 点击任何一个li都为 0下标


    post(self,api.setDefault,self.setDefaultList,(response)=>{

      self.getEntBank();

    })

  });

},


一只名叫tom的猫
浏览 3087回答 1
1回答

梦里花落0921

<li v-for="(item,index) in bankcardData" :key="index" @click="liClick(index)" :class="curindex === index ? 'active' : ''">赶脚你还一直再用jq的思想在编程,liClick(index){this.curindex === index;console.log(index)//获取li 的 index即下标}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript