简体   繁体   English

如何将JavaScript插入回显

[英]How to insert javascript into echo

Well i am trying to insert a javascript on php script 好吧,我正在尝试在php脚本上插入JavaScript

echo "['". $row['ac']. " ','<span onclick="alert(\'test\')">Click here!</span>',  new Date( ". $row['start']. " ),  new Date( ". $row['end']. " )], ";

but i am getting the below error: 但我收到以下错误:

( ! ) Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' (!)解析错误:语法错误,意外的T_STRING,期望为','或';' in /home/tregoal/public_html/skai/schedule/index2.php on line 156 在第156行的/home/tregoal/public_html/skai/schedule/index2.php中

i am trying to archive a result as below in order to use it on google charts. 我正在尝试将结果归档如下,以便在Google图表上使用它。

['DRIVER ',' 122 ', new Date( 2013,5,01,14,00,00 ), new Date( 2013,5,01,15,30,00 )], ['DRIVER','122',new Date(2013,5,01,14,00,00),new Date(2013,5,01,15,30,00)],

onClick事件初始化中转义双引号" ,而不是将new Date()打印为纯文本,就像使用变量对它进行连接一样:

echo "['" . $row['ac'] . " ','<span onclick=\"alert('test')\">Click here!</span>', " . new Date( $row['start']) . ", " . new Date($row['end']) . "], ";

您需要转义alert span中使用的双引号"

echo "['". $row['ac']. " ','<span onclick=\"alert(\'test\')\">Click here!</span>',  new Date( ". $row['start']. " ),  new Date( ". $row['end']. " )], ";

You're not escaping properly around onClick 您没有正确绕过onClick

Try this 尝试这个

echo "['". $row['ac']. " ','<span onclick=\"alert(\'test\')\">Click here!</span>',  new Date( ". $row['start']. " ),  new Date( ". $row['end']. " )], ";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM