0

setFocusOnError= true 的默认行为将焦点设置在错误字段上。但问题是窗口顶部有一个固定位置的横幅。由于哪个横幅隐藏了错误字段。如何覆盖 setFocusOnError 的默认工作,以便横幅和错误字段之间有一个边距?

在此处输入图像描述

4

1 回答 1

0
<script type="text/jscript">
        $(function () {
            // on first time page load
            if (typeof (Page_ClientValidate) != "undefined") {
                ValidatorSetFocus = CustomSetFocus;
            }
        });

        function CustomSetFocus(val, event) {

            var ctrl;
            if (typeof (val.controlhookup) == "string") {
                var eventCtrl;
                if ((typeof (event) != "undefined") && (event != null)) {
                    if ((typeof (event.srcElement) != "undefined") && (event.srcElement != null)) {
                        eventCtrl = event.srcElement;
                    }
                    else {
                        eventCtrl = event.target;
                    }
                }
                if ((typeof (eventCtrl) != "undefined") && (eventCtrl != null) &&
            (typeof (eventCtrl.id) == "string") &&
            (eventCtrl.id == val.controlhookup)) {
                    ctrl = eventCtrl;
                }
            }
            if ((typeof (ctrl) == "undefined") || (ctrl == null)) {
                ctrl = document.getElementById(val.controltovalidate);
            }
            if ((typeof (ctrl) != "undefined") && (ctrl != null) &&
        (ctrl.tagName.toLowerCase() != "table" || (typeof (event) == "undefined") || (event == null)) &&
        ((ctrl.tagName.toLowerCase() != "input") || (ctrl.type.toLowerCase() != "hidden")) &&
        (typeof (ctrl.disabled) == "undefined" || ctrl.disabled == null || ctrl.disabled == false) &&
        (typeof (ctrl.visible) == "undefined" || ctrl.visible == null || ctrl.visible != false) &&
        (IsInVisibleContainer(ctrl))) {
                if ((ctrl.tagName.toLowerCase() == "table" && (typeof (__nonMSDOMBrowser) == "undefined" || __nonMSDOMBrowser)) ||
            (ctrl.tagName.toLowerCase() == "span")) {
                    var inputElements = ctrl.getElementsByTagName("input");
                    var lastInputElement = inputElements[inputElements.length - 1];
                    if (lastInputElement != null) {
                        ctrl = lastInputElement;
                    }
                }
                if (typeof (ctrl.focus) != "undefined" && ctrl.focus != null) {
                    ctrl.focus();
                    Page_InvalidControlToBeFocused = ctrl;
                    var temp1=$(window).scrollTop();
                    temp1 = temp1 - 150;
                    $(window).scrollTop(temp1);
                }
            }

        }
    </script>
于 2013-10-14T12:39:45.853 回答