本文介绍了SyntaxError:在Firebug中的数字文字后立即启动标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 当我调用这个javascript函数时,我收到了这个错误: function kickUser(id_userChat){ $ .post(chatFuncs.php,{action:kick,id_user:id_userChat}); } 这个kickUser函​​数是为连接到我的聊天框的每个用户生成的,喜欢这个 $ listUsers。='< img src =imgUsers /'.$ DBClass-> nomImg($ rowUsers ['id_user'],$ posImg)。'height ='。$ heightImg。'width ='。$ widhImg。'/> < span class =styleMsg>'。$ rowUser ['nameUser']。'< / span>& nbsp; < a href =#class =BtnKickonClick =kickUser('。$ rowUsers ['id_user']。')> Kick< / a>< / br>'; 并且kick操作只是对我的数据库的更新,我从chatUsers中删除了用户table 如果我为$ rowUsers ['userName']更改$ rowUsers ['id_user'],则错误更改为: ReferenceError:'userName '未定义(我为此示例更改了'userName'用户的真实姓名)。解决方案 JavaScript中的标识符不能以数字开头。它们必须以字母 $ 或 _ 开头。 我猜这是来自: onClick =kickUser ( '$ rowUsers [ 'id_user']。')>踢< / A> 如果你想传递一个字符串,那么你需要引用传递的值。 // ---------------- v ---------- --------------- v onClick =kickUser(\'。$ rowUsers ['id_user']。'\)> Kick< / a> ; 我不知道PHP,所以也许你需要不同的转义,但这就是这个想法。 / p> I'm getting that error when I call this javascript function:function kickUser(id_userChat){$.post("chatFuncs.php", { action: "kick", id_user: id_userChat }); }this "kickUser" function is generated for every user connected to my chat box, like this$listUsers .= '<img src="imgUsers/'.$DBClass->nomImg($rowUsers['id_user'],$posImg).'" height="'.$heightImg.'" width="'.$widhImg.'"/><span class="styleMsg">'.$rowUser['nameUser'].'</span>&nbsp;<a href="#" class="BtnKick" onClick="kickUser('.$rowUsers['id_user'].')">Kick</a></br>';and the action "kick" is just an update to my database where I remove the user from my chatUsers tableIf I change $rowUsers['id_user'] for $rowUsers['userName'] the error changes to:ReferenceError: 'userName' is not defined (i changed the real name of the user for 'userName' just for this example). 解决方案 Identifiers in JavaScript can't begin with a number. They must begin with a letter, $ or _.I'm guessing it's coming from this:onClick="kickUser('.$rowUsers['id_user'].')">Kick</a>If you mean to pass a string, then you need to quote the value being passed.// ----------------v-------------------------vonClick="kickUser(\"'.$rowUsers['id_user'].'\")">Kick</a>I don't know PHP, so maybe you need different escaping, but this gives the idea. 这篇关于SyntaxError:在Firebug中的数字文字后立即启动标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-16 21:07