我如何在JavaScript中使用innerhtml? [英] How can I use innerhtml in JavaScript?

查看:134
本文介绍了我如何在JavaScript中使用innerhtml?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是我不知道如何显示我的表单的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆