jQuery   发布时间:2022-04-19  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了javascript – 滚动到jQuery-Textarea的顶部大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试向我的jQuery移动应用程序添加“更改日志”.如果出现错误,用户应该有能力,看看出了什么问题.因此我实现了一个带有textarea的弹出窗口(见下面的代码)
<!-- DIALOG Start-->
        <div data-role="popup" id="popupLog" data-overlay-theme="a" data-theme="b" style="max-width:400px;" class="ui-corner-all">
        <div data-role="header" data-theme="b" class="ui-corner-top">
        <h1>Logg-Einträge:</h1>
        </div>
        <div data-role="none" data-theme="b" class="ui-corner-bottom ui-content">
        <textarea style="height: 120px; max-height: 120px" readonly="readonly" data-mini="true" cols="40" rows="8" id="popupTextArea"></textarea>
        <a href="#" data-role="button" data-inline="true" id="btn_textArea" data-rel="BACk" data-theme="c">OK</a>    
        </div>
        </div>
        <!-- DIALOG End-->

此popUp充满了数据,并在单击特定按钮时打开:

$('#showLog').click(function() {
    $("#popupDialog").popup("close");
    // populate the textArea with the text
    $("#popupTextArea").text(sessionStorage.getItem("logStack"));
    // open popUp after a specific time
     setTimeout( function(){$('#popupLog').popup('open'); 
         },1000 );
});

到目前为止,所有功能都正常运行.问题是:当用户在textarea中向下滚动时,关闭popUp并重新打开它,滚动条的位置仍然相同 – 例如用户向下滚动到底部,关闭popUp并重新打开它 – popUp将位于textarea agein的底部.但是当我再次打开popUp时,我想总是把它放在textarea的顶端.为了实现这一点,我在这个popUp中实现了一个“Ok”-Button,如下所示,它关闭popUp并将scrollingTop设置为0:

$('#btn_textArea').click(function() {
// SetTing position of the textArea to "0" -> But doesn't work.....
     $('#popupTextArea').scrollTop(0);
     );
});

在这一点上有点兴奋,因为textArea的外观仍然相同.我需要刷新还是什么?我会非常感谢每一个帮助….

解决方法

您可以使用popupbeforeposition事件来操作textarea的scrollTop属性
$(document).ready(function(){

    $("#exampleWindow").on("popupbeforeposition",function(evt,ui){

        $(this).find("textarea").scrollTop(0);

    });

});

在这里你有一个带示例的jsfiddle,用一些文本填充textarea并测试在滚动后打开弹出窗口:http://jsfiddle.net/elchininet/eBp7S/

大佬总结

以上是大佬教程为你收集整理的javascript – 滚动到jQuery-Textarea的顶部全部内容,希望文章能够帮你解决javascript – 滚动到jQuery-Textarea的顶部所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。