“Gunakan PHP dalam file JavaScript” Kode Jawaban

cara menambahkan javascript ke file php

//this is my code 

you can add javascript to your code by using the echo statement and rap all 
your javascript between "" and if there is "" in the javascript code
then add \ before any "", and for the php inside rap it with ''
  
  
<?php
  echo "<script>document.write(\"hello world\")</script>"
?>
  
//other example

<?php
  $a = 5;
  echo "<script>document.write('$a')</script>"
?>

//other example
  
<?php 
$TokenData = Auth::user();

echo "<script type=\"text/javascript\">
             localStorage.setItem(\"id\", '$TokenData->id');
             localStorage.setItem(\"name\", '$TokenData->name');
             localStorage.setItem(\"email\", '$TokenData->email');
      </script> ";
Wide-eyed Wryneck

cara menulis php dalam file skrip

<script type="text/javascript" src="YourFunctions.js"></script>
<script type="text/javascript">
    functionOne(<?php echo implode(', ', $arrayWithVars); ?>);
    functionTwo(<?php echo $moreVars; ?>, <?php echo $evenMoreVars; ?>);
</script>
Dev

Gunakan PHP dalam file JavaScript

<script type="text/javascript">
	var myString = '<?php echo 1+1; ?>';
</script>
Undefined

cara menulis php dalam file skrip

<?php
$phpToJsVars = [
  'value1' => 'foo1',
  'value2' => 'foo2'    
];
?>
Dev

Jawaban yang mirip dengan “Gunakan PHP dalam file JavaScript”

Pertanyaan yang mirip dengan “Gunakan PHP dalam file JavaScript”

Lebih banyak jawaban terkait untuk “Gunakan PHP dalam file JavaScript” di HTML

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya