我有以下的jQuery:我怎樣才能調用JavaScript函數,並傳遞到它行的對象?
$('#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');
的前幾行此代碼現在工作得很好。
接下來,我願做同樣的事情上連續點擊事件,但通過使用JavaScript/jQuery代碼調用gridClickHandler。例如,在id =「row_25」的行上。有什麼辦法可以做到這一點?對不起,但我又困惑瞭如何處理$(this)。
這裏是我的代碼:
gridClickHandler.call(referenceToDOMElement);
// example: gridClickHandler.call($('#row_25').get(0));
注意該事件處理程序預計this
是一個DOM元素,而不是一個jQuery:
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的單擊事件處理程序。或者你想將處理程序綁定到特定的行嗎? – 2012-07-29 15:04:58
我還有其他的代碼,我會執行,一旦它完成我要回去,我需要再次執行gridClickHandler。但不是通過點擊。我想從我的其他代碼執行此操作,並將行中的信息傳遞給它。其他代碼知道該行的編號。 – Alan2 2012-07-29 15:09:36
啊,現在我明白了... – 2012-07-29 15:10:27