我添加了一个jquery函数来处理表行双击。由于某些原因,函数在双击上工作。有了jquery的新功能,我无法找到我所遗漏的内容。
我正在使用 Jquery函数:
$(document).ready(function () {
function addRowHandlers() {
var table = document.getElementById("shTable");
var rows = table.getElementsByTagName("tr");
for (i = 0; i < rows.length; i++) {
var currentRow = table.rows[i];
var createClickHandler =
function (row) {
return function () {
var cell1 = row.getElementsByTagName("td")[1];
//------------------------------------------
$.ajax({
type: "POST",
url: "BankSettings.aspx/GetBranchDetails",
data: "{'BranchCode':'" + cell1.innerHTML + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function (response) {
alert(response.d);
}
});
function OnSuccess(response) {
var data = response.d;
var myData = JSON.parse(data);
$('#<%=txtbranchname.ClientID%>').val(myData.BranchName);
$('#<%=txtbranchcode.ClientID%>').val(myData.BrCode);
$('#<%=txtreglocal.ClientID%>').val(myData.RegLocal);
$('#<%=txtregstate.ClientID%>').val(myData.RegState);
$('#<%=txtregcentral.ClientID%>').val(myData.RegCentral);
}
///-----------------------------------------
};
};
currentRow.dblclick= createClickHandler(currentRow);
}
}
window.onload = addRowHandlers();
});
答案 0 :(得分:0)
您正在分配createClickHandler
的返回值,而不是功能参考本身。
替换
currentRow.dblclick= createClickHandler(currentRow);
currentRow.dblclick = function ( event ){ createClickHandler( event.target ) };
使用jquery's dblclick 或
$( currentRow ).dblclick ( function( event ){ createClickHandler( event.target ) } );