我有以下的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