getElementById(element).innerHtml返回未定义 [英] getElementById(element).innerHtml returns undefined
问题描述
我正在尝试获取页面中元素的innerHtml,但innerHtml始终返回未定义.我已经测试过getElementById,没关系,该方法实际上可以找到要从中获取html的form元素.
I'm trying to get the innerHtml of an element in the page, but the innerHtml always returns undefined. I have already tested the getElementById and it's okay, the method can actually find the form element from which i want to get the html.
javascript函数将由一个按钮调用,它将打开一个新窗口,其中包含以下内容:
The javascript function will be called by a button, and it will open a new window with the form content:
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;
}
我已经检查了formElement变量值,它是:[object HTMLFormElement].
I've checked the formElement variable value and it's : [object HTMLFormElement].
推荐答案
该属性是 innerHTML
而不是 innerHtml
.JavaScript属性名称区分大小写.
The property is innerHTML
not innerHtml
. JavaScript property names are case-sensitive.
这篇关于getElementById(element).innerHtml返回未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!