특정 DOM 요소를 특정 JS 개체로 참조하려면 어떻게해야합니까? 예를 들어 고객의 배열이 있습니다. jQuery를 사용하여 각 고객에 대해 LI로 확인란을 만들고 고객 이름에 스팬을 사용합니다. 확인란을 클릭하면 고객 JS 객체에 대한 처리가 필요합니다. 질문, 어떻게이 JS 개체를 쉽게 얻을 수 있습니다. 현재 나는 다음과 같은 한 : 나는 JS의 세계를 믿고 jQuery를 그것을 할 더 우아한 방법이 존재DOM 요소에 대한 JS 개체 참조
$(customers).each(function(){
$("<li>").append($("<input type=\"checkbox\"").attr("id","chk_" + this.ID)).append($("<span>").text(this.Name)).appendTo("#ulCustomers");
});
$("#ulCustomers input[type=checkbox]").bind("click",function(){
var customerId = $(this).attr("id").replace("chk_","");
var CustomerObj = $(customers).filter(function() { return this.ID == customerId }).get(0);
myProcess(CustomerObj); //Two above two lines are just for select correct customer from array.
});
. 감사합니다.
물론, 어떻게 잊어 버릴 수 있습니다. 데이터() !!! :) 고마워. –