我如何在JavaScript中使用innerhtml? [英] How can I use innerhtml in JavaScript?
问题描述
我的问题是我不知道如何显示我的表单的innerhtml。
表单就像一个调查表单,一旦您点击提交按钮,所有我已经回答的内容将显示为一个摘要页面...
function displayResult(){
var first = document.getElementById(first).value;
var middle = document.getElementById(middle)。value;
var last = document.getElementById(last)。value;
alert(哦);
var maincontent = document.getElementById(content)。innerHTML;
maincontent =< p> +第一;
$ b
var maincontent = document.getElementById(content)。innerHTML;
maincontent =< p> +第一;
在第二行覆盖变量,而不是设置。的innerHTML
。这是你想要的:
var maincontent = document.getElementById(content);
maincontent.innerHTML =< p> +第一;
另外,您必须确保带有first,middle和last实际上是存在的,或者这可能导致 TypeError
。
My problem is that I don't know how to show the innerhtml of my form.
The form is like a survey form and once you clicked the submit button, all the contents I had answered would show like a summary page...
function displayResult() {
var first = document.getElementById("first").value;
var middle = document.getElementById("middle").value;
var last = document.getElementById("last").value;
alert("oh");
var maincontent = document.getElementById("content").innerHTML;
maincontent = "<p>" + first;
}
var maincontent = document.getElementById("content").innerHTML;
maincontent = "<p>" + first;
On the second line you're overwriting the variable, not setting the .innerHTML
. This is what you want:
var maincontent = document.getElementById("content");
maincontent.innerHTML = "<p>" + first;
Also, you must make sure the elements with ids of "first" "middle" and "last" actually exist, or this might cause a TypeError
.
这篇关于我如何在JavaScript中使用innerhtml?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!