HTML onclick with $(this)

我与调用一般的jQuery点击function有冲突,因此我需要在HTML元素本身上调用onclick事件,同时仍然可以使用$(this)

$('.item-main-section, .item-status').click( function () { var slideHeight = $(this).parent().children('.item-slide-section').height(); if ($(this).parent().height() > 50) { $(this).parent().animate({height: '50px'}, 300); $(this).parent().children('item-slide-section').animate({bottom: '0px'}, 300); } else { $(this).parent().animate({height: slideHeight + 50 + 'px'}, 300); $(this).parent().children('item-slide-section').animate({bottom: slideHeight - 5 + 'px'}, 300); $(this).parent().siblings('.item-wrapper').animate({height: '50px'}, 300); $(this).parent().siblings('.item-wrapper').children('item-slide-section').animate({bottom: '0px'}, 300); } }); 

而不是jquery点击我需要onclick =“thisFunction()”元素,但如果我摆脱第一行我失去了使用$(this)的能力。 这很难解释,但我希望对某人有意义。

您可以this元素作为参数传递:

 onclick="thisFunction($(this));" 

并在function上接收它作为元素:

 function thisFunction(element) { $this = element; //use it here }