Javascript滚动到底部不起作用

时间:2015-01-02 12:02:41

标签: javascript php html

我有这个脚本:

<?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>';
?>

javascript部分不起作用,每次刷新页面时,它都不会scrool到textarea底部,任何想法?

更新:我修改了我的脚本,但仍然无效

<?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>';
?>

2 个答案:

答案 0 :(得分:1)

尝试:

echo '<script type="text/javascript">
       var textarea = document.getElementById(\"wget\");
       textarea.scrollTop = textarea.scrollHeight;
      </script>';

(删除<<<HTML并重新格式化HTML字符串。)

答案 1 :(得分:0)

您可以尝试将Javascript移动到正文的底部并将其放入函数中:

(function() {
   var textarea = document.getElementById(\"wget\");
   textarea.scrollTop = textarea.scrollHeight;
})();