Javascript Jquery下一个相邻的选择器,带有$(this)
如何将相邻的选择器“+”与$(this)一起使用 我需要一个注释行的帮助//这不起作用:Javascript Jquery下一个相邻的选择器,带有$(this),javascript,jquery,Javascript,Jquery,如何将相邻的选择器“+”与$(this)一起使用 我需要一个注释行的帮助//这不起作用: $(".ExpandCollapse").click(function () { if ($(this).nextUntil('.Collapsable').is(':visible')) { //this doesnt work $(this + ".Collapsable").hide();
$(".ExpandCollapse").click(function () {
if ($(this).nextUntil('.Collapsable').is(':visible'))
{
//this doesnt work
$(this + ".Collapsable").hide();
}
else
{
//this doesnt work
$(this + ".Collapsable").show();
}
});
你能帮我一下吗
先谢谢你
致以最良好的祝愿
何塞使用
或者简单地说:
$(this).next().hide();
您还可以减少使用两条语句来隐藏和显示:
$(this).next().toggle();
这是对调用的DOM元素的引用。您不能将字符串添加到该字符串中
因此,您可以直接使用此
对其进行操作
$(this).hide();
或者您也可以从那里遍历DOM
$(this).next().hide();
$(this).prev().hide();
$(this).closest('.Collapsable').hide();
// another 200 methods
$(this).next().hide();
$(this).prev().hide();
$(this).closest('.Collapsable').hide();
// another 200 methods