php - SyntaxError : identifier starts immediately after numeric literal. 将 php 变量传递给 JavaScript

标签 php javascript html web literals

我试图将两个变量传递给 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 上的其他帖子。他们都无济于事。 非常感谢您帮助解决此错误。

最佳答案

您需要引用用户 ID

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

关于php - SyntaxError : identifier starts immediately after numeric literal. 将 php 变量传递给 JavaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17392619/

相关文章:

php - 我如何允许空白字段被我的数据库接受为空?

php - 无法仅选择包含数据的列

javascript - getUserMedia - 无法同时从两个浏览器访问摄像头

javascript - JSON 字符串化崩溃

javascript - 使用 Javascript 或 Ruby 对大小进行分类的算法

javascript - 如何正确检查是否所有表单元素都填充了 JavaScript

在 IE 8 上呈现 HTML 5 CSS3

PHP 如何启动安全 session

ubuntu - php.ini 未在 Ubuntu 16.04.3 LTS 上重新加载

javascript - 将 Bootstrap 添加到现有标题以进行折叠并使用 Bootstrap 动画