我有一个带有onkeypress事件的html表格,如:
<tr onclick="RowOnClickEvent();" class="PikerBodyRowStyle" onkeypress="return Test(event);">
<td class="PikerCellStyle" style="width:10px; text-align:left"> <input type="checkbox" value="@item.AccountHeadID" name="chkBox" /> </td>
<td class="PikerCellStyle" style="width:150px; text-align:left">@Html.DisplayFor(modelItem => item.AccountCode)</td>
<td class="PikerCellStyle" style="width:160px; text-align:left">@Html.DisplayFor(modelItem => item.AccountHeadName)</td>
</tr>
我的JavaScript功能如下:
function Test(e) {
// debugger;
if (e.keyCode == 13) {
if (SelectedItemID > 0) {
$.ajax({
type: "GET",
dataType: "json",
url: '@Url.Action("GetData", "ChartsOfAccount")',
data: { id: SelectedItemID },
contentType: "application/json; charset=utf-8",
success: function (data) {
alert(data);
},
error: function (xhr, status, error) {
alert(error);
}
});
}
return false;
}
}
它在Internet Explorer中运行良好,但Mozilla Firefox不能正常工作。
答案 0 :(得分:0)
更改
onkeypress="return Test(e);"
到
onkeypress="return Test(event);"
答案 1 :(得分:0)
您无法向tablerow提供javascript操作。相反,您可以使用一些按钮或链接来创建您的操作。你也可以把它放在td标签中。 javascript操作在那里工作。