몇 가지 jQuery 함수가 있습니다.jQuery selector의 반환 목록에 대한 참조를 얻는 방법?
rfx.jQuery(function(){
rfx.jQuery(".form-row.errors").blur(some_function(this))
});
그러나 'this'는 HTMLDocument이며 선택기 반환 값 목록이 아닙니다. 요소 목록에 대한 참조는 어떻게 얻을 수 있습니까?
몇 가지 jQuery 함수가 있습니다.jQuery selector의 반환 목록에 대한 참조를 얻는 방법?
rfx.jQuery(function(){
rfx.jQuery(".form-row.errors").blur(some_function(this))
});
그러나 'this'는 HTMLDocument이며 선택기 반환 값 목록이 아닙니다. 요소 목록에 대한 참조는 어떻게 얻을 수 있습니까?
선택 결과 즉, rfx.jQuery(".form-row.errors")
은 반환 된 요소의 배열입니다. 당신의 흐림 이벤트 그러나
rfx.jQuery(".form-row.errors").blur(function(){
//`this` is the element reference...
});
입력 상자 사이 JS fiddle Example 및 탭을 참조하십시오. blur()
함수 내에서 다시 선택
A) ...
rfx.jQuery(function(){
rfx.jQuery(".form-row.errors").blur(function(){
// `this` is the element which is blurring
var formRowErrors = rfx.jQuery(".form-row.errors") //select again within the blur function
});
});
B) 클로저를 사용 :
당신이 중 하나가없이 흐림 내에서 전체 선택을 액세스 할 수 없습니다 ...
rfx.jQuery(function(){
var formRowErrors = rfx.jQuery(".form-row.errors");
rfx.jQuery(".form-row.errors").blur(function(){
// `this` is the element which is blurring
// formRowErrors is the jQuery selection of all form-row.errors
});
});
그러나,이 두 번째 방법에서, var formRowErrors
은을 바인딩 할 때 선택 만을 포함합니다. 즉, "라이브"가 아닙니다.
상황에 문제가 있습니다. 당신이
rfx.jQuery(function(){
rfx.jQuery(".form-row.errors").blur(some_function(this))
});
을 할 경우이 난 당신이 모든 액세스 할 수 있다고 생각하지 않습니다 rfx.jQuery
의 상황에 맞는 것 동안
anonymus 기능은
this
로rfx.jQuery(".form-row.errors")
의 결과를해야합니다 * blur * 함수 내의 selector * 요소. 'jQuery (".form-row.errors")'를 다시 호출해야한다. (코드에서 DOM을 변경하지 않는다면 이전에 var에 저장해야한다.) – JMax'some_function'을 blur 이벤트에 바인드 하시겠습니까, 아니면 바인드 할 다른 함수를 반환합니까 *? 현재 당신은 후자를하고 있습니다. –
some_function을 blur 이벤트에 바인딩하고 싶습니다. – sunprophit