我有一個簡單的PHP變量,我需要將它帶到JavaScript部分。將數據從PHP傳遞到JavaScript
代碼:
<?php
if ($p == 'home') { $selected == '0'; }
if ($p == 'music') { $selected == '1'; }
if ($p == 'videos') { $selected == '2'; }
if ($p == 'search') { $selected == '3'; }
if ($p == 'about') { $selected == '4'; }
if ($p == 'contact') { $selected == '5'; }
?>
<script type="text/javascript">
//SYNTAX: tabdropdown.init("menu_id", [integer OR "auto"])
tabdropdown.init("colortab", $selected) <-- $selected is the variable I want to carry over
</script>
像魅力一樣工作,謝謝! – rackemup420