繁体   English   中英

使用jQuery保留滚动条位置

[英]Retaining scrollbar position using jquery

我有一个Java函数,

private GroupsSelector group(LabourInputReportCriteria.Level level) {
            HtmlSelectBooleanCheckbox box = new HtmlSelectBooleanCheckbox();
            boolean isSelected = selections.isGroupSelected(level);
            box.setSelected(isSelected);
            // box.setDisabled(isDaySelectedOnFirst(level));
            String id="groupBy" + level.getClass().getSimpleName();
            box.setId(id);

            box.setOnclick("submit()");


            box.addValueChangeListener(u.addExpressionValueChangeListener("#{reportSearchCriteriaModel.groupBy}"));
            HtmlOutputText labelComponent = new HtmlOutputText();

            labelComponent.setValue(getGroupSelectionValue(level));
            tr().td();
            html(box);


            html(" ");

            html(labelComponent);
            //html("<span id='"+id+ "'></span>");

            //html("<script> function resetGroupsSelector() {  var x = document.getElementById('search_report_form:groupByWeekLevel'); alert(x); } </script>");

            endTd().endTr();
            return this;
        }

每当我单击复选框时,就会调用sumbit(),并且它在后端具有某些功能。 现在,我的问题是,每当我单击一个复选框时,滚动条的位置就会向上移动,即它位于页面顶部。 我想避免这种情况。 我想保持滚动条的位置不变。 我应该怎么做?

我尝试添加以下代码,但效果不佳。

<script type="text/JavaScript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js" >
var addTweet = function() {
    var scrollPosition = $(document).scrollTop();
    $('#results9016').prepend($newTweet);
    $('html, body').scrollTop(scrollPosition);
}
</script>

请帮忙。

在您单击时调用的函数中,您可以说

function submit(event) {
   event.preventDefault();
   ...
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM