[英]basic php question. adding javascript to .php page
嗨,我不是 php 開發人員,我以前從未接觸過它。 但我被要求將谷歌購物車跟蹤代碼添加到網站。 當有人完成訂單然后被發送到finishorder.php。 當我 go 完成訂單時。php 文件看起來像這樣:
include(dirname(__FILE__)."/init.php");
$GLOBALS['ISC_CLASS_ORDER'] = GetClass('ISC_ORDER');
$GLOBALS['ISC_CLASS_ORDER']->HandlePage();
這對我來說就像服務器腳本(來自 .net 背景),所以我想我不能在這里添加 javascript,php 如何決定獲取此頁面的布局? 如何將 javascript 代碼添加到此頁面。
你可以這樣做:
include(dirname(__FILE__)."/init.php");
$GLOBALS['ISC_CLASS_ORDER'] = GetClass('ISC_ORDER');
$GLOBALS['ISC_CLASS_ORDER']->HandlePage();
echo '<script type="text/javascript">YOUR JS HERE</script>';
或者
<?php
include(dirname(__FILE__)."/init.php");
$GLOBALS['ISC_CLASS_ORDER'] = GetClass('ISC_ORDER');
$GLOBALS['ISC_CLASS_ORDER']->HandlePage();
?>
<script type="text/javascript">YOUR JS HERE</script>
唔?
但我認為 HandlePage() 方法會對我們的頁面做一些事情,所以我會看看這個方法 Class ISC_ORDER->handlePage() 它做了什么......然后你可以在適當的地方在這個方法中回顯你......
編輯:
<?php
echo '<script type="text/javascript">//<!--
alert("Hello to multiline JS script");
alert("Do You get it?");
//--></script>';
?>
您可以在 php 代碼中添加 javascript 為
<?php echo "<script> alert('this is a javascript code')</script>"; ?>
您可以通過兩種方式在 PHP 頁面中添加腳本
第一種方法是在PHP標簽中添加
<?php
//PHP CODE
if($_POST['submit']){
echo '<script>alert('Hello')</script>';
}
?>
第二種方式是在PHP代碼后添加
<?php
//PHP CODE
?>
<script>
alert('Hello');
</script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.