나는 다음과 같은 jQuery를 가지고 : 어떻게 자바 스크립트 함수를 호출하고 행 객체에 전달할 수 있습니까?
$('#dataTable').on('click', 'tbody tr', clickHandler);
다음은이 코드는 지금 아주 잘 작동 내 gridClickHander
function gridClickHandler(event) {
$(oTable.fnSettings().aoData).each(function() {
$(this.nTr).removeClass('row_selected');
});
$(this).addClass('row_selected');
var rk = $(this).attr('data-rk');
var pk = $(this).attr('data-pk');
의 처음 몇 줄입니다.
다음 행에서 click 이벤트와 동일한 작업을 수행하지만 gridClickHandler를 호출하는 javascript/jQuery 코드를 사용하고 싶습니다. 예 : id = "row_25"인 행 내가 할 수있는 방법이 있니? 미안하지만 다시 나는 $ (this)를 다루는 방법에 대해 혼란 스럽다. 이벤트 핸들러가 jQuery를 this
는 DOM의 요소가 될 것으로 기대하고하지 않는 것이
gridClickHandler.call(referenceToDOMElement);
// example: gridClickHandler.call($('#row_25').get(0));
참고 : .call
[MDN] 또는 .apply
[MDN]를 사용하여 this
을 명시 적으로 설정할 수 있습니다
if (obj.entity == "City") {
var html = obj.$form.find("#select-topic").html();
var indx = obj.$form.find("#select-topic").index()
$("#input_TempRowKey_" + obj.rownum).html(html);
$("#input_TempRowKey_" + obj.rownum).eq(indx).attr('selected', 'selected');
var title = obj.$form.find("#Title").val();
$("#input_Title_" + obj.rownum).val(title);
$("tr#row_" + obj.rownum).attr("data-rk", json.rowKey);
// here I need to do the same as though a user just clicked on rownum
}
문제가 무엇인지 이해하지 못했습니다. jQuery를 사용하여 click 이벤트 핸들러를 이미 바인딩하고 있습니다. . 또는 핸들러를 특정 행에 바인드 하시겠습니까? –
나는 실행할 다른 코드를 가지고 있으며 일단 끝나면 다시 돌아 가야하고 gridClickHandler를 다시 실행해야 할 것이다. 그러나 클릭하지 마십시오. 다른 코드에서이 작업을 수행하고 행의 정보를 전달하려고합니다. 다른 코드는 행 번호를 알고 있습니다. – Alan2
아, 이제 알았습니다 ... –