gpt4 book ai didi

javascript - 如何将 JavaScript 实现为 PHTML

转载 作者:行者123 更新时间:2023-12-03 09:33:54 26 4
gpt4 key购买 nike

我对 PHP 和 PHTML 都很陌生,我该如何将 JavaScript 实现到 PHTML 中?这是我试图将其实现到的文件(viewer.phtml)

    <?php
if ($type == "jpeg") {
$stype = "jpg";
} else {
$stype = $type;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title><?php echo APP_NAME . " - $file.$stype"; ?></title>
<link rel="stylesheet" href="/site/images/assets/css/style.css">
</head>

<body>
<h1><?php echo "$file.$type"; ?></h1>

<div class="container">
<img src="/images/<?php echo "$type/$file.$stype"; ?>" alt="<?php echo "$file.$stype"; ?>">
</div>

<?php
$time = microtime();
$time = explode(' ', $time);
$time = $time[1] + $time[0];
$finish = $time;
$total_time = round(($finish - $start), 4);
?>


</body>
</html>

最佳答案

要添加脚本,请使用脚本标记。将它注入(inject)到你的 head 标签中,这样你的 head 可能看起来像这样

     <head>
<meta charset="UTF-8">
<title><?php echo APP_NAME . " - $file.$stype"; ?></title>
<link rel="stylesheet" href="/site/images/assets/css/style.css">
<script>
//you Javascript code here
</script>
</head>

          <head>
<meta charset="UTF-8">
<title><?php echo APP_NAME . " - $file.$stype"; ?></title>
<link rel="stylesheet" href="/site/images/assets/css/style.css">
<script type="text/javascript" src="your_js_file_location_here"></script>
</head>

希望这对你有帮助

关于javascript - 如何将 JavaScript 实现为 PHTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31396473/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com