Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/454.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Can';t调用JavaScript函数-ReferenceError:Can';找不到变量_Javascript_Function_Variables - Fatal编程技术网

Can';t调用JavaScript函数-ReferenceError:Can';找不到变量

Can';t调用JavaScript函数-ReferenceError:Can';找不到变量,javascript,function,variables,Javascript,Function,Variables,这实际上是一个AdobeAIR应用程序,但由于我遇到的问题是非常基本的JavaScript,我想我应该把它放在这里 代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head

这实际上是一个AdobeAIR应用程序,但由于我遇到的问题是非常基本的JavaScript,我想我应该把它放在这里

代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>KM Ciclo de Servicio</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href="css/ciclo.css" rel="stylesheet" type="text/css" />
<script src="script/jquery-1.7.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
function changefield()
{
    #('#ciclo').append('ASD');
}
</script>
</head>
<body oncontextmenu="return false;">
<div id="topMenu">
    <button class="menuItem" id="new" title="Nuevo"><img src="images/new.png" alt="Nuevo"/></button>
    <button class="menuItem" id="save" title="Guardar"><img src="images/save.png" alt="Guardar"/></button>
    <button class="menuItem" id="open" title="Abrir"><img src="images/open.png" alt="Abrir"/></button>
    <input type="text" value="Momento cambiado" onkeypress="changefield()"/>
        <div style="display: inline-block; float: right;">
        Nuevo:
        <button class="menuItem" id="momento">Momento</button>
        <button class="menuItem" id="atributo">Atributo</button>
    </div>
</div>
<div id="main" align="center">
    <div id="ciclo"></div>
</div>
<script src="script/init.js" type="text/javascript"></script>

</body>
</html>    
错误显示:

引用错误:找不到变量:changefield
onkeypress at app:/index.html:19

我已经检查了一些关于JavaScript函数的教程,以确保(包括w3schools的教程)没有任何错误。我正是按照这些教程的建议调用函数的


有什么想法吗?

正确的语法是:

function changefield()
{
    $('#ciclo').append('ASD');
}
这是一个javascript语法错误:

#('#ciclo').append('ASD');

这导致未定义changefield函数。

问题可能是jQuery创建了
$
变量,而不是

因为
#
应该是
$

function changefield() {
    $('#ciclo').append('ASD');
}

SyntaxError
导致未创建
changefield
函数,因此内联
onkeypress
无法找到它。

你说得对!真不敢相信我在代码中犯了这样的错误哈哈。嗯,谢谢你指出这一点,它现在可以工作了。该死的,但是你的名字很烦人,除了台式机/笔记本电脑之外,根本不可能在任何设备上直接回复。@DaveNewton是的,我是个麻烦制造者。对不起,不是麻烦,只是故意排挤,这有点违背主题。不管怎样。@DaveNewton:故意排除?哇,听起来真是麻烦。我想我最好在StackOverflow让我在27天内改变它。在那之前,我们都被困住了(实际上不是,你可以从其他SE站点复制你的个人资料来绕过这个特定的障碍。
#('#ciclo').append('ASD');
function changefield()
{
    $('#ciclo').append('ASD');
}
function changefield() {
    $('#ciclo').append('ASD');
}