如何在jquery中转到下一个选项卡时卸载js脚本?
我有一个使用 jquery-ui 的带有五个选项卡的网站。 每个加载一个单独的 jQuery 脚本。 现在,当我加载第二个选项卡并转到第三个选项卡时,第二个选项卡中的 js 仍然保持活动状态,并干扰我在第三个选项卡空间中的操作。
有人可以解释一下为什么在更改到第三个选项卡时第二个选项卡中的 js 仍然保持活动状态以及如何避免这种行为?
I have a site with five tabs using jquery-ui. Each loads an individual jQuery script. Now when I have loaded the second tab and go to the third tab the js out of the second tab still remains active and disturbs my actions in the third tab space.
Can someone explain me why the js out of the second tab still stays active when changing to the third tab and how I can avoid such behaviour?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将脚本加载到页面后,它会保持活动状态,直到页面刷新。
我不知道卸载,但您当然可以根据特定脚本的内容禁用它的操作。 您能否发布导致问题的脚本示例?
编辑:
例如,如果您有一个依赖于您所在选项卡的脚本,则可以使用位于特定索引的选项卡来调节脚本中的操作。 演示语法:
//will onlyexecute action if you are in current tab
to get that variable (
tabs_ui_index
) you can do like this:此代码将“tabsselect”事件绑定到元素tabbed 并在每次用户更改选项卡时将变量设置为当前索引的选项卡。
另外,如果您加载了为不再存在的按钮设置单击事件的脚本,或者您现在用于不同目的的按钮,则可以取消绑定事件:
我希望这会有所帮助。 如果您还有其他问题,请告诉我。
Once you have loaded a script onto the page, it remains active until the page refreshes.
I don't know about unloading, but you can certainly disable the actions of a certain script depending on what it is. Could you post an example of the script causing the issues?
EDIT:
For example, if you have a script that is dependent on the tab you are in, you can condition the actions in the script with the tabs being at a certain index. A demo syntax:
//will only execute action if you are in current tab
to get that variable (
tabs_ui_index
) you can do something like this:This code binds a "tabsselect" event to the element that is tabbed and sets the variable to the currently indexed tab every time a user changes a tab.
Also, you can unbind events, if you loaded a script that set a click event for a button that no longer exists, or that you are using for a different purpose now:
I hope this helps. Let me know if you have any other questions.