他们做得到正确解析,但是你所指定的那些错误的使用。 Javascript不能区分引用字符串变量和引用来包装“onclick”值,它认为onclick过早结束。
为了区分他们,你必须逃避它们。在括号内使用\"
。
echo "<a class='fa fa-ban fa-2x cancelClass' onClick='cancelClass(\"$id\", \"$formattedDate\", \"$time\")'></a><p class='text-center'>".$formattedDate." @ $time</p>";
应该这样做。
另外,不要使用echo整个字符串,只需输出大部分是直接的:
?> //temporarily stop interpreting the file as PHP, so the next bit will be output directly as raw HTML
<a class='fa fa-ban fa-2x cancelClass' onClick='cancelClass("<?php echo $id;?>", "<?php echo $formattedDate; ?>", "<?php echo $time;?>")'></a><p class='text-center'>".$formattedDate." @ $time</p>
<?php //continue with PHP
PHP使单引号和双引号有所不同。你可以尝试在使用 –
'"'一致的https://stackoverflow.com/questions/25916943/uses-for-the-quot-entity-in-html –