我试图将两个变量传递给 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/