Javascript asp.net的下一页是焦点始终移动到底部
我有两页。第一页中的“下一页”按钮将显示第二页。第二页的焦点总是向下移动。所以我需要使用滚动条将光标置于顶部。我想把重点放在最上面。我的focus-handler.js如下:Javascript asp.net的下一页是焦点始终移动到底部,javascript,asp.net,Javascript,Asp.net,我有两页。第一页中的“下一页”按钮将显示第二页。第二页的焦点总是向下移动。所以我需要使用滚动条将光标置于顶部。我想把重点放在最上面。我的focus-handler.js如下: var lastFocusedControlId = ""; function focusHandler(e) { document.activeElement = e.originalTarget; } function appInit() { if (typeof (window.addE
var lastFocusedControlId = "";
function focusHandler(e) {
document.activeElement = e.originalTarget;
}
function appInit() {
if (typeof (window.addEventListener) !== "undefined") {
window.addEventListener("focus", focusHandler, true);
}
setFirstControl()
Sys.WebForms.PageRequestManager.getInstance().add_pageLoading(pageLoadingHandler);
Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(pageLoadedHandler);
}
function pageLoadingHandler(sender, args) {
lastFocusedControlId = typeof (document.activeElement) === "undefined"
? "" : document.activeElement.id;
}
function focusControl(targetControl) {
if (Sys.Browser.agent === Sys.Browser.InternetExplorer) {
var focusTarget = targetControl;
if (focusTarget && (typeof (focusTarget.contentEditable) !== "undefined")) {
oldContentEditableSetting = focusTarget.contentEditable;
focusTarget.contentEditable = false;
}
else {
focusTarget = null;
}
try {
targetControl.focus();
if (focusTarget) {
focusTarget.contentEditable = oldContentEditableSetting;
}
}
catch (err) { }
}
else {
targetControl.focus();
}
}
function pageLoadedHandler(sender, args) {
if (typeof (lastFocusedControlId) !== "undefined" && lastFocusedControlId != "") {
var newFocused = $get(lastFocusedControlId);
if (newFocused) {
focusControl(newFocused);
}
}
}
function setFirstControl() {
var bFound = false;
// for each form
for (f = 0; f < document.forms.length; f++) {
// for each element in each form
for (i = 0; i < document.forms[f].length; i++) {
// if it's not a hidden element
if (document.forms[f][i].type != "hidden") {
// and it's not disabled
if (document.forms[f][i].disabled != true) {
try {
// set the focus to it
document.forms[f][i].focus();
var bFound = true;
}
catch (er) {
}
}
}
// if found in this element, stop looking
if (bFound == true)
break;
}
// if found in this form, stop looking
if (bFound == true)
break;
}
}
Sys.Application.add_init(appInit);
var lastFocusedControlId=“”;
函数聚焦处理器(e){
document.activeElement=e.originalTarget;
}
函数appInit(){
if(typeof(window.addEventListener)!=“未定义”){
window.addEventListener(“焦点”,focusHandler,true);
}
setFirstControl()
Sys.WebForms.PageRequestManager.getInstance().add_pageLoading(pageLoadingHandler);
Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(pageLoadedHandler);
}
函数pageLoadingHandler(发送方,参数){
lastFocusedControlId=typeof(document.activeElement)=“未定义”
?“”:document.activeElement.id;
}
功能焦点控制(目标控制){
if(Sys.Browser.agent==Sys.Browser.InternetExplorer){
var focusTarget=目标控制;
if(focusTarget&&(typeof(focusTarget.contentEditable)!=“未定义”)){
oldContentEditableSetting=focusTarget.contentEditable;
focusTarget.contentEditable=false;
}
否则{
focusTarget=null;
}
试一试{
targetControl.focus();
如果(聚焦目标){
focusTarget.contentEditable=oldContentEditableSetting;
}
}
捕获(错误){}
}
否则{
targetControl.focus();
}
}
函数pageLoadedHandler(发送方,参数){
if(typeof(lastFocusedControlId)!=“未定义”&&lastFocusedControlId!=”){
var newFocused=$get(lastFocusedControlId);
如果(新聚焦){
聚焦控制(新聚焦);
}
}
}
函数setFirstControl(){
var bFound=假;
//每种形式
对于(f=0;f
我在aspx页面中使用focus-handler.js,如下所示。这与您之前提出的问题不一样吗?()我的代码后面,我以如下方式编程填充各种控件:对于索引为整数=1到100的Dim b作为新的LiteralControl(“”),Dim c作为新的LiteralControl(label1.Text().Trim())panel1.controls.Add(b)panel1.controls.Add(c)NextNo-Darren,我对java脚本印象深刻。这个问题更多地集中在javascript中的bug上,这对我来说是个问题。