本文介绍了jQuery-专注于TR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,因此,我正在制作一个插件,以允许对网站中的表格进行内联编辑,到目前为止,我已经完成了大部分工作,但似乎无法将Focusing排除在表格之外.因此,如果某人已完成编辑并开始编辑新行,或者只是单击该行之外的内容,则它应该保存并恢复正常.但是,如果我在行上使用模糊,则没有响应,但是如果我在元素上使用模糊,则当人们从一个元素交换到另一个元素时会触发

Okay, so I'm making a plugin to allow inline editing of tables in my website, going great so far, I've got most of it done, but I can't seem to get Focusing out of the table right. So if someone is done editing and starts editing a new row or just clicks out of the row, it should save and go back to normal. But if I use blur on the row, there's no response, but if I use blur on the element, it triggers when people swap from one element to another

但是,如果我在该行上使用focusout,则即使有人单击同一行,只要有人离开该元素,它也会触发.事件变量下也没有任何内容可以告诉我它将焦点放在哪个元素上,因此我无法与当前行进行比较,以查看它们是否只是在该行中单击.

But if I use focusout on the row, it triggers whenever someone leaves the element as well, even if they click in the same row. Nor is there anything under the event variable that tell me what element it's setting the focus on, so I can't compare with the current row to see if they're just clicking with in the row.

我正在考虑将其保存在Enter/Mouse上,单击保存"按钮/开始编辑另一行,但是我宁愿使其生效,因为这似乎是一种更好的方法.以为有人吗?好吗?

I'm thinking of having it save on Enter/Mouse Click to a Save button/Start editing another row, but I'd rather get this to work, as it seems to be a much better method of doing it. Thought anyone? Please?

推荐答案

我将通过为整个文档绑定单击处理程序,然后在其他单击事件中添加stopPropagation()调用来处理您的请求.我设置了一个小提琴来演示: http://jsfiddle.net/NwftK/

I would handle your request by binding a click handler for the whole document, and then adding a stopPropagation() call within my other click events. I've setup a fiddle to demonstrate: http://jsfiddle.net/NwftK/

<table border="1" width="200">
    <tr id="myRow"><td>Hello</td><td>World</td></tr>
</table>

还有jQuery:

$(function () {
    $("#myRow").on('click', function (e) {
       $(this).css('background-color', 'blue');
        e.stopPropagation();
    });

    $(document).on('click', function () {

       $("#myRow").css('background-color', 'red');
    });

});

这篇关于jQuery-专注于TR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 06:59