我需要取消设置 jQuery .toggle(odd,even) 的状态

发布于 2024-09-05 07:14:23 字数 183 浏览 4 评论 0原文

我的表格单元格中有可以打开和关闭的项目。

外部按钮接受点击并通过 ajax 提交选定的单元格值。

问题是我想重置所选单元格的切换状态。

我可以轻松取消突出显示,但随后需要双击才能触发正确的切换。

.toggle(odd, Even) 可以通过外部调用重置或循环吗?

谢谢

I have items in a table cell that gets toggled on and off.

An external button accepts a click and submits the selected cell values via ajax.

The problem is that I want to reset the toggle state for the selected cells.

I can easily unset the highlighting, but then need a double click to trigger the correct toggle.

Can the .toggle(odd, even) be reset or cycled via an external call?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

变身佩奇 2024-09-12 07:14:23

我没有测试过,但是可以这样做吗?

//reset the toggle state<br>
      $('#tablecell').unbind('click').toggle(fn1, fn2);<br>
      $('#tablecell').toggle(fn1, fn2);

I have not tested but, could it be done like this?

//reset the toggle state<br>
      $('#tablecell').unbind('click').toggle(fn1, fn2);<br>
      $('#tablecell').toggle(fn1, fn2);
忆依然 2024-09-12 07:14:23

我最终通过选择已经切换的元素列表解决了这个问题。

然后我调用 .click 。

这似乎是一个解决方法,但因为我无法触发切换状态。我就这样解决了。

I eventually solved this by selecting the already toggled list of elements.

I then call a .click on it.

Which seems like a bit of a workaround, but since I can't trigger the state of toggle. I settled for this.

新雨望断虹 2024-09-12 07:14:23

.toggle().show().hide() 之间的交替相同,因此只需调用 .show().hide() 取决于所需的“重置”状态。

如果您使用 .toggle() 循环处理程序,则只需取消绑定并重新绑定切换事件即可。

.toggle() is the same as alternating between .show() and .hide() so just call .show() or .hide() depending on what the desired "reset" state is.

if you are using .toggle() to cycle through handlers then just unbind and rebind the toggle event.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文