Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/409.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/2/github/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
Javascript java脚本中的方法和调用多个方法_Javascript - Fatal编程技术网

Javascript java脚本中的方法和调用多个方法

Javascript java脚本中的方法和调用多个方法,javascript,Javascript,为什么我不能从custom中调用changeBackground()和toNormal()作为方法 当我将toNormal作为一个方法删除,并将其作为一个独立函数放在custom之外时,代码可以工作,但在custom中却不能 一个对象可以容纳多个方法吗 var自定义= { changeBackground:函数(){ var text=document.getElementById(“para”).style.backgroundColor=“红色”; } toNormal:function()

为什么我不能从custom中调用changeBackground()和toNormal()作为方法

当我将toNormal作为一个方法删除,并将其作为一个独立函数放在custom之外时,代码可以工作,但在custom中却不能

一个对象可以容纳多个方法吗

var自定义= { changeBackground:函数(){ var text=document.getElementById(“para”).style.backgroundColor=“红色”; } toNormal:function(){ var text=document.getElementById(“para”).style.backgroundColor=“”; } } 这是一些文本


在您的
更改背景
功能之后,您忘记了
。对象列表需要用逗号分隔

var自定义={
changeBackground:函数(){
var text=document.getElementById(“para”).style.backgroundColor=“红色”;

},//请正确格式化您的代码,您将看到,缺少逗号。请在您的英文文本中更加精确…“as method from custom”-自定义什么?香蕉、苹果、函数、对象???检查此项。 this is some text