Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
$myVar = "6542";という php 変数があります。
</head>JavaScript で値を取得できるようにするために、サイトのタグの前にどこでエコーすることができますか (そして、html の問題をトリガーしません)。
</head>
タイ
タグの上に投げてください。単純。
<script type="text/javascript>var myvar = '<?=htmlspecialchars($myVar);?>';</script>
ページのどこにでも配置できますが、必ずしも上に配置する必要はありません
<script>タグで囲むと、ほぼどこでも(HEADコンテンツが最適な場所です) :
<script>
<script> var myVar = "6542"; </script>