echo heredoc php
问题描述:
我想在heredoc中回显来自php的javascript。但由于美元符号,它不工作。逃避美元符号,但它仍然无法正常工作。有谁能帮忙解决这个问题吗?谢谢。它给出了一个错误echo heredoc php
Uncaught ReferenceError: $ is not defined
<?php
echo '<!DOCTYPE html> <html> <head><title> hello world </title> </head> <body>' ;
$testscript=<<<EOT
<script>
\$('input[type=radio][name=gender]').change(function() {
alert(this.value);
});
</script>
EOT;
echo $testscript;
echo '</body></html>' ;
?>
答
jQuery库未在脚本加载
加上''您尚未引用jQuery库 – Thamilan
您可以使用jQuery代替$ for javascript部分 –
jQuery尚未加载,因此未定义错误。或者将它改为'jQuery(...)。change(..'。或者在DOM上运行 - ''jQuery(document).ready(function(){... do your stuff ..});' – Darren