Javascript滚动至底部不';行不通
我有这个剧本:Javascript滚动至底部不';行不通,javascript,php,html,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>
<?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部分不起作用,它不会在每次刷新页面时都在文本区域底部滚动,有什么想法吗
更新:我将脚本修改为这样,但仍然不起作用
<?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>';
?>
试试:
echo'
var textarea=document.getElementById(\“wget\”);
textarea.scrollTop=textarea.scrollHeight;
';
(删除
您可以尝试将Javascript移动到正文底部,并将其放入函数中:
(function() {
var textarea = document.getElementById(\"wget\");
textarea.scrollTop = textarea.scrollHeight;
})();
我只是想说,我把基本代码放到了一个小提琴里,Javascript可以工作…,所以问题是PHP,而不是Javascript。
(function() {
var textarea = document.getElementById(\"wget\");
textarea.scrollTop = textarea.scrollHeight;
})();