由js参数中的数字引起的意外TOKEN非法

UNEXPECTED TOKEN ILLEGAL caused by a number in js parameter

本文关键字:意外 TOKEN 非法 数字 js 参数      更新时间:2023-09-26

我有以下代码片段:

<input type="file" name="040_featured_4_image" onchange="angular.element(this).scope().uploadFile(this, 040_featured_4_image)" style="display: none">

我想知道为什么这个代码段不起作用,但当我将参数040_featured_4_image上的数字替换为forty_featured_four_image时,该函数可以完美地工作

040_featured_4_image

在JavaScript中,变量名不能以数字开头。

Quentin在回答中已经说过,不能使用以数字开头的变量名。想一个很小的例子来说明为什么这是不可能的:

int 040d = 10;
double a = 040d;

现在你期望a的值是多少?

变量不能以数字开头,我读到的最奇怪的是angular.element()....的用法,为什么不使用简单的<input ng-change="uploadFile($event, ....)">