난 "이"중첩 자바 스크립트 함수 "이"
if(tabNav === true){
$("." + tabNavClass).show();
tabNavItem.first().addClass("active");//active class on first li
tabNavItem.each(function(i){
$(this).attr("rel",(i + 1));
});
tabNavItem.on("click", function(e){
tabNavClick();
//this works, but i don't want it defined here. i want it in the tabNavClick() function
//var data = $(this).attr("rel");
//console.log(data);
e.preventDefault();
});
}
//tab nav function
function tabNavClick(){
// REGISTERS UNDEFINED HERE B/C LOSES SCOPE OF "THIS". FIX?!
var that = $(this);
var data = that.attr("rel");
console.log(data);
tabNavItem.removeClass("active");//remove existing active class
의 적절한 범위를 잃는다} 중첩 기능이 상실;
나는 var that = $(this)
을 시도했지만 작동하지 않으며 .call이이 시나리오에서 작동하지 않을 것이라고 생각합니다. 내가 어떻게 $(this).attr("rel");
rel # 값 내가 undefined
대신 원하는 반환하도록합니까? 함수에
이 tabNavClick' 이미 클릭 핸들러와 같은 기록 '처럼 보이는, 그래서를 등록하지 왜 그렇게? :) –
@Jack 정직하게, b/c 나는 내가하는 일을 모른다. 첫 번째 플러그인을 작성하려고합니다. 클릭 핸들러가 무엇인지는 알지만 어떻게 등록하면이 상황에서 도움이됩니까? – heyjohnmurray
제 답변에서 설명했습니다. –