警报无法按下按钮

-1 html javascript

我很好奇为什么当我点击按钮时它没有警报5.谁知道为什么? http://jsfiddle.net/bm8dd/

<center>
   <input id='1' type='text' onfocus='1();'>
   <input id='2' type='text' onfocus='2();'>
   <br>
   <br>
   <button type='button' onclick='3()'>Button</button>
</center>
<script>
    var x = 5;
    function 3() {
        alert(x);
    }
</script>
Run Code Online (Sandbox Code Playgroud)

Mr.*_*ien 7

因为您无法使用数字启动函数名称.

此外,它与id (不是现在)相同,但它的一般做法是不用数字启动id.

考虑适当地命名您的函数,field1()或者field2()在其他人读取您的代码时这是有意义的,这称为命名约定.