简体   繁体   English

使onclick location.href在echo PHP中工作

[英]Make onclick location.href work in echo php

I am really stumped on this. 我真的为此感到困惑。 I can not get it to work. 我无法正常工作。 It seems that there is something wrong with my syntax. 我的语法似乎有问题。 Any help will be much appreciated. 任何帮助都感激不尽。

<?php
    echo '<tr onClick="location.href="http://executivevalet.net.au/app/calendar.php?action=display_event&oid='.$eid[$a].'""><td>Link</link</tr>
?>

You need to use escape quotes using \\ 您需要使用\\来使用转义引号
Backslashes are used in PHP to escape special characters within quotes. 在PHP中,反斜杠用于转义引号内的特殊字符。 As PHP does not distinguish between strings and characters 由于PHP不能区分字符串和字符

try this: 尝试这个:

echo "<tr onClick='location.href=\"http://executivevalet.net.au/app/calendar.php?action=display_event&oid=".$eid[$a]."\"'><td>".$date[$a]."</td><td>".$eid[$a]."</td><td>".$subject[$a]."</td></tr>";

Escape your double quotes with a backslash (or PHP interprets it as the end of a string)! 用反斜杠转义双引号(或PHP将其解释为字符串的结尾)!

$a=0;
while(mysql_num_rows($result)>$a){
    echo "<tr onClick=\"location.href='http://executivevalet.net.au/app/calendar.php?action=display_event&oid=<?php echo $eid[$a]; ?>'\"><td>".$date[$a]."</td><td>".$eid[$a]."</td><td>".$subject[$a]."</td></tr>";
$a++;
}

As both Cagy79 and Alessandro Minoccheri have said - your PHP syntax is wrong. 正如Cagy79和Alessandro Minoccheri所说的那样-您的PHP语法错误。

You should be getting errors in your web server logs, and you can always check your syntax using PHP on the command line (if applicable): " php -l <filename>.php " 您应该在Web服务器日志中遇到错误,并且始终可以在命令行上使用PHP(如果适用)检查语法:“ php -l <filename>.php

The error will be something like this: 该错误将是这样的:

PHP Parse error:  syntax error, unexpected T_STRING, expecting ',' or ';' in test.php on line 8
Errors parsing test.php

It's telling you that there was an unexpected string (textual data) on line 8. It was expecting either a comma or semi-colon. 它告诉您第8行上有一个意外的字符串(文本数据)。它期望是逗号或分号。 This is logical, as echo could take a comma to separate arguments - and the semi-colon would complete the line. 这是合乎逻辑的,因为echo可以使用逗号来分隔参数-分号将完成这行。

Either of the proposed solutions from the above people will fix your issue. 上述人员提出的任何解决方案都可以解决您的问题。

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

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