Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/464.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 在html中调用js方法_Javascript_Html - Fatal编程技术网

Javascript 在html中调用js方法

Javascript 在html中调用js方法,javascript,html,Javascript,Html,我对js中的类以及如何在html文件中调用它有问题 class SetProp(){ 建造商(高度、宽度){ 高度=高度; 这个。宽度=宽度; } 函数getHeight(){ 返回此参数。高度; } 函数getWidth(){ 返回这个.width; } } 你好 prop=新的SetProp(10001000); 你好 html属性width和height不能分配给函数,您需要做的是编写一个函数,该函数将在单击按钮时或DOM加载后返回宽度和高度,使用Javascript使用选择器修改元素

我对js中的类以及如何在html文件中调用它有问题

class SetProp(){
建造商(高度、宽度){
高度=高度;
这个。宽度=宽度;
}
函数getHeight(){
返回此参数。高度;
}
函数getWidth(){
返回这个.width;
}
}

你好
prop=新的SetProp(10001000);
你好

html属性
width
height
不能分配给函数,您需要做的是编写一个函数,该函数将在单击按钮时或DOM加载后返回宽度和高度,使用Javascript使用选择器修改元素的属性,如下所示:

document.getElementById('canvas').style.width =prop.getWidth() ;
document.getElementById('canvas').style.height =prop.getHeight() ;
您的getHeight()和getWidth()函数是私有的,不作为主类原型的登录,因此如果您想访问它们,您应该像这样使用主类原型:

'class SetProp(height,width){
    this.height = height;
    this.width = width;

}
 SetProp.prototype.getHeight=function(){
       return this.height;
  }
  SetProp.prototype.getWidth=function(){
       return this.width;
  }'

您是否使用任何模板引擎来呈现视图?我没有使用任何模板现在我看到一个未捕获的语法错误:函数getHeight()后出现意外标识符。{您只删除
函数
键:
函数getHeight(){..
getHeight(){..
函数getWidth(){…
to
getWidth(){…