首页 > 代码库 > 循环中点击单个事件(巧用this,指向当前对象)

循环中点击单个事件(巧用this,指向当前对象)

<em id=‘show‘ value="http://www.mamicode.com/<?php echo $member[‘phone‘]; ?>" class="sui"><a href="http://www.mamicode.com/#">查看归属地</a></em><em id=‘show‘ value="http://www.mamicode.com/<?php echo $member[‘phone‘]; ?>" class="sui"><a href="http://www.mamicode.com/#">查看归属地</a></em><em id=‘show‘ value="http://www.mamicode.com/<?php echo $member[‘phone‘]; ?>" class="sui"><a href="http://www.mamicode.com/#">查看归属地</a></em><em id=‘show‘ value="http://www.mamicode.com/<?php echo $member[‘phone‘]; ?>" class="sui"><a href="http://www.mamicode.com/#">查看归属地</a></em><em id=‘show‘ value="http://www.mamicode.com/<?php echo $member[‘phone‘]; ?>" class="sui"><a href="http://www.mamicode.com/#">查看归属地</a></em><em id=‘show‘ value="http://www.mamicode.com/<?php echo $member[‘phone‘]; ?>" class="sui"><a href="http://www.mamicode.com/#">查看归属地</a></em>

 

Jquery:

//也可以用类 $(".sui").bind(‘click‘, function(event) $("em").bind(‘click‘, function(event) {    build = $(this);    var phone = $(this).attr("value");    $.ajax({        url: "<?php echo SITE_ADMIN_URL . ‘/member/get_phone/‘; ?>"+phone,        type: ‘Get‘,        dataType: ‘‘,        success:function(result){            build.html("<em>"+result+"<em>");        }    });});

 

循环中点击单个事件(巧用this,指向当前对象)