我的問題很簡單,但在PHP代碼中使用javascript有點困難。在php中使用javascript代碼
這裏是我的代碼:
<script>var showdiv1 = 0;</script>
--- some html codes ---------
<script>showdiv1 = showdiv1 + 1;</script>
<div class="col-md-12 box" id= "div<?php echo "<script type='text/javascript'>showdiv1</script>"?>"><br />
我得到的輸出。
<div id="div<script type='text/javascript'>showdiv1</script>" class="col-md-12 box">
預期輸出:
<div id="div1" class="col-md-12 box">
請指教,我究竟做錯了什麼?
感謝
您不能使用客戶端腳本來這樣的服務器端腳本。 –
PHP在發送到瀏覽器之前在服務器上執行。 Javascript在瀏覽器呈現頁面時執行。你不能像使用它們一樣在同一時間執行它們,因爲它們不是。 –