js $(this)相关

来源:互联网 发布:徐老师淘宝店地址是啥 编辑:程序博客网 时间:2024/05/18 00:43
HTML:
<div id="test"><input  value='asdasd' type="hidden"/><a  class="mobile_remove" id="1234">aa</a></div>

JQ:
 
$(document).ready(function() {       //1、被调用函数
       var removeMobile = function() {      //alert("1");       alert( $(this).parent().html());
}
       //2、使用1的函数(使用匿名函数导致$(this)无效)
      $(".mobile_remove").click(function(){removeMobile();});
 
       //3、使用1的函数(直接赋值,$(this)有效)
       $(".mobile_remove").click(removeMobile);}


 

原创粉丝点击