【问题标题】:SyntaxError: identifier starts immediately after numeric literal. Passing php variable to JavaScriptSyntaxError:标识符在数字文字之后立即开始。将 php 变量传递给 JavaScript
【发布时间】:2013-06-27 20:59:25
【问题描述】:

我正在尝试将两个变量传递给 JavaScript 函数:输入本身和用户 ID。我使用输入的 onclick 属性调用该函数。

 echo "<input type = 'submit' class = 'replyButton' id = 'replyButton'
 value = 'reply' onclick = 'insertComment(this, $user_id);'>";

变量进入 JavaScript 函数:

function insertComment(input, user)
{
     //use input and user id to carry out tasks.
} 

给出的错误消息是在输入的 onclick 中对“insertComment()”的函数调用处。错误信息如下所示:

SyntaxError: identifier starts immediately after numeric literal    

       insertComment(this, 9f60d869342a);

我尝试了多个引号和点组合,并查看了 StackOverFlow 上的其他帖子。他们都无济于事。 非常感谢您帮助解决此错误。

【问题讨论】:

标签: php javascript html web literals


【解决方案1】:

你需要引用用户ID

echo "<input type = 'submit' class = 'replyButton' id = 'replyButton'
 value = 'reply' onclick = 'insertComment(this, \"$user_id\");'>";

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多