the textbox in the datagrid is has an id like DataGrid1__ctl3_aaaa, so tryif (e.id.indexOf("aaaa") > 0 && event.keyCode == 13) window.alert("bzg");
if (e.id=="aaaa" && event.keyCode == 13) window.alert("bzg") 改为: if (e.id.indexOf("aaaa")>=0 && e.tagName=="INPUT" && event.keyCode == 13) window.alert("bzg");这里的aaaa就是你的TextBox的id。
to 思归: 为什么是一个id
you could haveDataGrid1__ctl0_aaaa DataGrid1__ctl1_aaaa DataGrid1__ctl2_aaaa .....
your textbox is in a template, right? DataGrid implements INamingContainer, ASP.NET will assign each control inside DataGrid a unique id/name, and the normal convention is to use "Parent1ID_Parent2ID....ChildID" for id and ""Parent1ID:Parent2ID:....ChildID" for name
just open the HTML source code from the browser, and you will understand
window.alert("bzg");
window.alert("bzg")
改为:
if (e.id.indexOf("aaaa")>=0 && e.tagName=="INPUT" && event.keyCode == 13)
window.alert("bzg");这里的aaaa就是你的TextBox的id。
为什么是一个id
DataGrid1__ctl1_aaaa
DataGrid1__ctl2_aaaa
.....