[英]how to Set focus to a Image Button while Page Load?
I have can I make an Image button have focus while loading the page. 我可以在加载页面时使图像按钮具有焦点。 I have set the Image button's TabIndex value to "-1" in script side, while pressing tab key the tab index is changing for all the controls exactly inclding Image button, but I want the Image button to be focused while loading the page. 我在脚本端将Image按钮的TabIndex值设置为“-1”,同时按Tab键,所有控件的选项卡索引都在改变,正好包含Image按钮,但我想在加载页面时聚焦Image按钮。
Is there any difference between Image button and other controls? Image按钮和其他控件之间有什么区别吗? What property or function i've to use to set focus? 我用什么属性或功能来设置焦点?
I am using the below line to set focus, but it's not working: 我使用下面的行设置焦点,但它不起作用:
ScriptManager1.SetFocus(imgSearch1);
Thanks in advance. 提前致谢。
简单的方法是创建一个javascript函数并在body标签中将其命名为onLoad。
Try this 尝试这个
imgSearch1.Focus();
or setting the focus first before setting its tabIndex: 或者在设置tabIndex之前先设置焦点:
var ele;
function imgSetFocus() {
ele = document.getElementById('<%= imgSearch1.ClientID %>');
ele.focus();
setTimeout(function(){ ele.tabIndex = -1 }, 500);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.