0

我有两个相同的 ASP.net Web 应用程序项目。javascript 资源文件未在一个项目中加载,而在另一个项目中成功加载。我无法理解为什么以及如何解决。我正在使用以下内容来使用 javascript。目的是解决这里描述的失去焦点的问题参考链接

        <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
        <Scripts>
            <asp:ScriptReference Path="~/Scripts/FixFocus.js"  NotifyScriptLoaded="true" /></Scripts> </asp:ToolkitScriptManager>

以下是js文件

                var lastFocusedControlId = "";

    function focusHandler(e) {
    document.activeElement = e.originalTarget;
}

    function appInit() {
    if (typeof(window.addEventListener) !== "undefined") {
        window.addEventListener("focus", focusHandler, true);
    }
    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;
        }
        targetControl.focus();
        if (focusTarget) {
            focusTarget.contentEditable = oldContentEditableSetting;
        }
    }
    else {
        targetControl.focus();
    }
}

function pageLoadedHandler(sender, args) {
    if (typeof(lastFocusedControlId) !== "undefined" && lastFocusedControlId != "") {
        var newFocused = $get(lastFocusedControlId);
        if (newFocused) {
            focusControl(newFocused);
        }
    }
}

Sys.Application.add_init(appInit); 
4

1 回答 1

0

我离开了第一个项目并开始在第二个项目中工作,这是相同的。现在它运行良好

于 2014-02-13T07:35:14.413 回答