在不使用任何双引号的情况下创建JavaScript警报代码

时间:2017-11-04 06:19:02

标签: javascript php html5 javascript-events alert

此代码是我的网页的一部分:

<span onclick=alert('Name:$commenter_name <br>Email:$commenter_email <br> Rate:$commenter_rate <br>Comment time:$currentdate <br>Comment:$commenter_comment')>$commenter_name:$commenter_comment
    <span class='post_time'>$currentdate</span>
</span>

JavaScript警报无效。

我想让这段代码正常工作,不使用任何双引号

这是我的整个PHP代码:

<?php
    if (isset($_POST['post'])){    
        $commenter_name = $_POST["commenter_name"];
        $commenter_email = $_POST["commenter_email"];
        $commenter_rate = $_POST["commenter_rate"];
        $commenter_comment = $_POST["commenter_comment"];
        $currentdate = date('d F Y');
        $fianl = "Name:$commenter_name <br>Email:$commenter_email <br> Rate:$commenter_rate <br>Comment time:$currentdate<br>Comment:$commenter_comment";
        $filename = getcwd() . "/Comma comments.php"; 
        $line_i_am_looking_for = 2; 
        $lines = file( $filename , FILE_IGNORE_NEW_LINES ); 
        $lines[$line_i_am_looking_for] =    "
        <tr>
            <td>
                 <span onclick=alert('$fianl')>$commenter_name$commenter_comment
                      <span class='post_time'> $currentdate </span>
                 </span><hr><br>
           </td>
        </tr>";
       file_put_contents( $filename , implode( "\n", $lines ) );
    }
?>

请帮忙

1 个答案:

答案 0 :(得分:1)

我自己做了答案。 这是代码:

<?php
if (isset($_POST['post'])){

        $commenter_name = $_POST["commenter_name"];
        $commenter_email = $_POST["commenter_email"];
        $commenter_rate = $_POST["commenter_rate"];
        $commenter_comment = $_POST["commenter_comment"];
        $currentdate = date('d F Y');
        $fianl = "Name\:$commenter_name \\n Email\:$commenter_email \\n Rate\:$commenter_rate \\n Comment time\:$currentdate \\n Comment\:$commenter_comment";
$filename = getcwd() . "/Comma comments.php"; 
$line_i_am_looking_for = 2; 
$lines = file( $filename , FILE_IGNORE_NEW_LINES ); 
$lines[$line_i_am_looking_for] =    "
<tr>
 <td colspan='2'>
 <span onclick=\"alert('$fianl')\">$commenter_name$commenter_comment <span class='post_time'> $currentdate </span></span><hr>
<br>
</td></tr>";
file_put_contents( $filename , implode( "\n", $lines ) );
}
?>

\"告诉PHP脚本忽略双引号。 \\n告诉PHP脚本忽略\n。  这就是全部。