HTML Onclick 与 $(this) [英] HTML Onclick with $(this)
本文介绍了HTML Onclick 与 $(this)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我与调用通用 jQuery click 函数有冲突,因此我需要在 HTML 元素本身上调用 onclick 事件,同时仍然能够使用 $(this)
I have a conflict with calling the general jQuery click function and so I need to call an onclick event on the HTML element itself while still being able to use $(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);
}
});
我需要元素上的 onclick="thisFunction()" 而不是 jquery 单击,但是如果我摆脱第一行,我将失去使用 $(this) 的能力.这很难解释,但我希望它对某人有意义.
Instead of the jquery click i need onclick="thisFunction()" on the elements but if I get rid of the first line I lose the ability to use $(this). It's hard to explain but I hope it makes sense to someone.
推荐答案
您可以将 this
元素作为参数传递:
you can pass this
element as parameter:
onclick="thisFunction($(this));"
并在函数上将其作为元素接收:
and on function recieve it as element:
function thisFunction(element)
{
$this = element;
//use it here
}
这篇关于HTML Onclick 与 $(this)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文