简体   繁体   English

IE 8,jQuery 1.7.1 $(element).parents(selector)也返回同级

[英]IE 8, jQuery 1.7.1 $(element).parents(selector) returns siblings also

I have a form with this layout: 我有一个具有这种布局的表格:

<div class='detail'>
    <div>
        <input type='button' class='save' />
    </div>
</div>
<div class='detail'>
    <div>
        <input type='button' class='save' />
    </div>
</div>
<div class='detail'>
    <div>
        <input type='button' class='save' />
    </div>
</div>

When $(".save").click() is triggered. $(".save").click()被触发时。 I call $(this).parents(".detail") 我叫$(this).parents(".detail")

For IE, this is what happens: - The parent <div class='detail'> is selected as well as the previous <div class='detail'> siblings. 对于IE,这是发生的情况: -父<div class='detail'>被选择以及先前<div class='detail'>兄弟姐妹。

For FF, this is what happens: - Only the parent <div class='detail'> is returned. 对于FF,将发生以下情况:-仅返回父<div class='detail'>

The correct functionality I'm looking for is what FF is doing. 我正在寻找的正确功能是FF正在做什么。

May I know how to do a work-around for IE. 我可以知道如何为IE解决问题。

Thank you. 谢谢。

EDIT: This is the click event handler: 编辑:这是单击事件处理程序:

$(".product_details .button_save_draft").bind("click", function (event) {
    event.preventDefault();
    alert($(this).parents(".product_details").length);
});

I don't have any idea why the above is working as described above, but as a solution probably you need to look at .closest() 我不知道为什么上面的工作如上所述,但是作为解决方案,您可能需要查看.closest()

$(".product_details .button_save_draft").bind("click", function (event) {
    event.preventDefault();
    alert($(this).closest(".product_details").length);
});

Also see the difference between them 还可以看到它们之间区别

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM