Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/391.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 getElementById(element).innerHtml返回未定义的_Javascript_Html - Fatal编程技术网

Javascript getElementById(element).innerHtml返回未定义的

Javascript getElementById(element).innerHtml返回未定义的,javascript,html,Javascript,Html,我试图获取页面中某个元素的innerHtml,但innerHtml总是返回未定义的。我已经测试了getElementById,没关系,该方法实际上可以找到我想要从中获取html的表单元素 javascript函数将由一个按钮调用,它将打开一个包含表单内容的新窗口: function Popup(data){ var formElement = document.getElementById(data); var content = formElement.inn

我试图获取页面中某个元素的innerHtml,但innerHtml总是返回未定义的。我已经测试了getElementById,没关系,该方法实际上可以找到我想要从中获取html的表单元素

javascript函数将由一个按钮调用,它将打开一个包含表单内容的新窗口:

function Popup(data){           
   var formElement = document.getElementById(data);
   var content = formElement.innerHtml;
   var mywindow = window.open('', 'my div', 'height=400,width=600');
   mywindow.document.write('<html><head><title>Checklist</title>');
   mywindow.document.write('</head><body >');
   mywindow.document.write(content);
   mywindow.document.write('</body></html>');
   mywindow.print();
   mywindow.close();
   return true;
}
功能弹出窗口(数据){
var formElement=document.getElementById(数据);
var content=formElement.innerHtml;
var mywindow=window.open(“”,'my div','height=400,width=600');
mywindow.document.write(“检查表”);
mywindow.document.write(“”);
mywindow.document.write(内容);
mywindow.document.write(“”);
mywindow.print();
mywindow.close();
返回true;
}

我已经检查了formElement变量值,它是:[object HTMLFormElement]。

属性是
innerHTML
而不是
innerHTML
。JavaScript属性名称区分大小写

这是一个多么愚蠢的错误,非常感谢,我是Javascript新手,以前没有注意到这一点。