jQuery의 다음 탭으로 이동할 때 JS 스크립트를 내리는 방법은 무엇입니까?

StackOverflow https://stackoverflow.com/questions/1211426

  •  06-07-2019
  •  | 
  •  

문제

jQuery-UI를 사용하는 5 개의 탭이있는 사이트가 있습니다. 각각은 개별 jQuery 스크립트를로드합니다. 이제 두 번째 탭을로드하고 세 번째 탭으로 이동하면 두 번째 탭에서 JS가 여전히 활성 상태로 유지되며 세 번째 탭 공간에서 내 동작을 방해합니다.

누군가가 세 번째 탭으로 변경할 때 두 번째 탭의 JS가 여전히 활성화되는 이유와 그러한 동작을 피할 수있는 방법을 설명 할 수 있습니까?

도움이 되었습니까?

해결책

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

if(tabs_ui_index == 0){
  //do something
}

to get that variable (tabs_ui_index) you can do something like this:

 $('#mytabs').bind('tabsselect', function(event, ui) {
     tabs_ui_index = ui.index;
 });

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:

$("#mybutton").unbind("click");

I hope this helps. Let me know if you have any other questions.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top