选择框与 .mouseup 一起使用返回 false 问题
我正在关注本教程:
http:// /www.9lessons.info/2011/03/live-table-edit-with-jquery-and-ajax.html
我的补充是大部分内容是ajax/json/dynamic。我添加了一个选择框,它也是动态填充的。当我尝试在选择下拉列表中选择某些内容时,它会自动关闭。我认为由于这个原因:
$(".editbox").mouseup(function(){
return false
});
我尝试对此使用一些变体:
$('input[type=select]').click(function(event){event.stopPropagation()});
但我比我目前的理解所允许的更深入了兔子洞。 任何建议将不胜感激。
I am following this tutorial:
http://www.9lessons.info/2011/03/live-table-edit-with-jquery-and-ajax.html
My addition is most content is ajax/json/dynamic. I have added a select box which is also populated dynamically. When I try to select something in the select dropdown it automatically closes. I assume due to this:
$(".editbox").mouseup(function(){
return false
});
I have tried to use some variation on this:
$('input[type=select]').click(function(event){event.stopPropagation()});
But I am further down the rabbit hole than my current understanding allows.
Any suggestions would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过使用 if 语句将代码包装在 tr 的 click 事件中来解决此问题,该 if 语句检查实际单击了哪个元素。这将导致您的代码仅在用户直接单击具有适当类的
或
时隐藏/显示输入。这将允许您摆脱“.editbox”mouseup 事件处理程序。
jsFiddle (小提琴中的第一行显示一个选择框,而不是仅两个输入,因此您可以看到这段代码有效。ajax 调用也在小提琴中进行了注释。)
上面的相关代码是:
不要忘记删除此代码:
编辑: 您需要在 ' 中执行类似的操作文档'点击处理程序。除了此处之外,如果目标具有“editbox”类,您将忽略点击。
You can solve this by wrapping the code in your tr's click event with an if statement that checks which element was actually clicked. This will cause your code to only hide/show the inputs when the user clicks directly on a
<td>
or<span>
with the appropriate class. That will allow you to get rid of the '.editbox' mouseup event handler.jsFiddle (The first row in the fiddle displays a select box instead of just two inputs so you can see that this code works. The ajax call is also commented in the fiddle.)
The relevant code above is:
Don't forget to remove this code:
Edit: You'll need to do something similar in the 'document' click handler. Except here, you're ignoring the clicks if the target has the 'editbox' class.