0

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 では動作しません。

4

2 に答える 2

0

変化する

onkeypress="return Test(e);"

onkeypress="return Test(event);"
于 2012-09-18T03:24:13.603 に答える
0

テーブル行に JavaScript アクションを与えることはできません。代わりに、ボタンまたはリンクを使用してアクションを作成できます。tdタグに入れることもできます。JavaScript アクションはそこで動作します。

于 2012-09-18T04:44:46.460 に答える