SyntaxError:标识符在数字文字后立即启动。将php变量传递给JavaScript [英] SyntaxError: identifier starts immediately after numeric literal. Passing php variable to JavaScript

查看:172
本文介绍了SyntaxError:标识符在数字文字后立即启动。将php变量传递给JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将两个变量传递给JavaScript函数:输入本身和用户标识。我使用输入的onclick属性调用函数。

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

变量进入JavaScript函数:

 函数insertComment(输入,用户)
{
//使用输入和用户ID执行任务。





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

  SyntaxError:标识符在数字文字后立即启动

insertComment(this ,9f60d869342a);

我已经尝试了多个报价和点组合,并且检查了StackOverFlow上的其他帖子。他们都无济于事。
您在解决此错误方面的帮助非常感谢。

解决方案

您需要引用用户标识

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


I am trying to pass in two variables to a JavaScript function: the input itself and the user id. I call the function using the onclick attribute of the input.

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

The variables go into a JavaScript function:

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

The error message given is at the function call to 'insertComment()' in the onclick of the input. The error message looks like this:

SyntaxError: identifier starts immediately after numeric literal    

       insertComment(this, 9f60d869342a);

I have tried multiple quote and dot combinations and have checked the other posts on StackOverFlow. They were all to no avail. Your help in resolving this error is greatly appreciated.

解决方案

you need to quote the user id

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

这篇关于SyntaxError:标识符在数字文字后立即启动。将php变量传递给JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆