使用 knockoutjs 或 jquery 将焦点设置到 gridview 中的第一行
Set focus to the first row in a gridview using knockoutjs or jquery
我在 ASP.NET 中有一个动态网格,只要单击“搜索”按钮,就会使用 Knockout.js 为其获取数据。加载网格后,用户可以单击任何行以在弹出窗口中检查与该行相关的详细信息。
我想在这里实现的是,单击搜索按钮并加载网格中的数据后,焦点应设置为第一行,Enter 键应触发单击事件(当鼠标点击时弹出)。
提前致谢!!
注意:使用 Knockout js 和 jquery 在 asp.net 中获取和绑定数据
$("#search").click(function(){
$("#first-row").focus();
})
//active your row
if( $("#first-row").is(":focus")){
$("#first-row").addClass("active") //maybe a style for this active row
}
$(document).keypress(function(e) {
if(e.which == 13 && $("#first-row").hasClass("active")) {
//redirect or show a div..
}
});
类似的东西?
P.S : 我不知道是否可以关注 div 或 tr ^^
您可以使用 Knockouts hasFocus 绑定
hasFocus 绑定将 DOM 元素的焦点状态与视图模型 属性 链接起来。这是双向绑定,因此:
如果您将视图模型 属性 设置为 true 或 false,关联的元素将变得有焦点或没有焦点。
Try this:
$(document).ready(function(){
var column = $("#<%=GridView1.ClientID %>").find("tr:eq(1)");
column.focus();
});
If it fails
try
ClientIDMode="Static"
我在 ASP.NET 中有一个动态网格,只要单击“搜索”按钮,就会使用 Knockout.js 为其获取数据。加载网格后,用户可以单击任何行以在弹出窗口中检查与该行相关的详细信息。
我想在这里实现的是,单击搜索按钮并加载网格中的数据后,焦点应设置为第一行,Enter 键应触发单击事件(当鼠标点击时弹出)。
提前致谢!!
注意:使用 Knockout js 和 jquery 在 asp.net 中获取和绑定数据
$("#search").click(function(){
$("#first-row").focus();
})
//active your row
if( $("#first-row").is(":focus")){
$("#first-row").addClass("active") //maybe a style for this active row
}
$(document).keypress(function(e) {
if(e.which == 13 && $("#first-row").hasClass("active")) {
//redirect or show a div..
}
});
类似的东西?
P.S : 我不知道是否可以关注 div 或 tr ^^
您可以使用 Knockouts hasFocus 绑定
hasFocus 绑定将 DOM 元素的焦点状态与视图模型 属性 链接起来。这是双向绑定,因此:
如果您将视图模型 属性 设置为 true 或 false,关联的元素将变得有焦点或没有焦点。
Try this:
$(document).ready(function(){
var column = $("#<%=GridView1.ClientID %>").find("tr:eq(1)");
column.focus();
});
If it fails
try
ClientIDMode="Static"