[英]Javascript scroll to bottom doesn't work
I have this script: 我有这个脚本:
<?php
header("refresh: 5;");
include 'theme.php';
ceklogin();
css();
echo <<<HTML
<script type="text/javascript">
var textarea = document.getElementById(\"wget\");
textarea.scrollTop = textarea.scrollHeight;
</script>
HTML;
echo " Wget log :<br>";
echo "<textarea name=\"text-info\" rows=\"30\" id=\"wget\" cols=\"90\" readonly style=\"font-family: Arial;font-size: 7pt;\" >";
$datalines = file ("wget.log");
foreach ($datalines as $zz) {
echo $zz; }
echo "</textarea></div>";
foot();
echo '
</div>
</body>
</div>
</html>';
?>
the javascript part doesn't work, it won't scrool to bottom on the textarea every time it refreshes the page, any ideas? javascript部分不起作用,每次刷新页面时,它都不会在文本区域的底部显示出来,有什么想法吗?
Update: I modified my script to be like this but still doesn't work 更新:我将脚本修改为这样,但仍然无法正常工作
<?php
header("refresh: 5;");
include 'theme.php';
ceklogin();
css();
echo '<script type="text/javascript">
var textarea = document.getElementById(\"wget\");
textarea.scrollTop = textarea.scrollHeight;
</script>';
echo " Wget log :<br>";
echo "<textarea name=\"text-info\" rows=\"30\" id=\"wget\" cols=\"90\" readonly style=\"font-family: Arial;font-size: 7pt;\" >";
$file = file_get_contents('/www/wget.log');
echo $file;
echo "</textarea></div>";
foot();
echo '
</div>
</body>
</div>
</html>';
?>
Try: 尝试:
echo '<script type="text/javascript">
var textarea = document.getElementById(\"wget\");
textarea.scrollTop = textarea.scrollHeight;
</script>';
(Removed the <<<HTML
and reformatted the HTML string.) (删除了
<<<HTML
并重新格式化了HTML字符串。)
You could try moving your Javascript to the bottom of the body and putting this in a function: 您可以尝试将Javascript移动到正文底部,然后将其放入函数中:
(function() {
var textarea = document.getElementById(\"wget\");
textarea.scrollTop = textarea.scrollHeight;
})();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.