2013-06-18 108 views
1

继承人我的HTML表单:JavaScript/HTML:如何将用户输入显示到html正文中?

<label>Name:</label><input type ="text" input id="myName" /><br> 
<label>Street:</label><input type="text" input id="myStreet" /><br> 
<label>City:</label><input type="text" input id="myCity" /><br> 
<label>State:</label> <input type="text" input id="myState" /><br> 
<label>Zip:</label> <input type="text" input id="myZip" /><br> 

<input type="submit" value="Submit" onclick="myAlert()"> 
</form> 
//my myAlertFunc (from external file) 

function myAlert(){ 
    var person = new Person(document.getElementById('myName').value, document.getElementById("myStreet").value, document.getElementById("myCity").value, document.getElementById("myState").value, document.getElementById("myZip").value); 
    alert(person.getFullAddress()); 
} 

//and my getFullAddress proto from my Person class 

Person.prototype.getFullAddress = function() { 
    return ("Hi, my name is" + " " + this.name + "," + " " + "and my address is:" + " " + this.street + "," + this.city + "," + this.state + "," + this.zip); 
}; 

现在的onclick的myAlertFunc提醒用户输入值。我如何在HTML体内显示这些值?我知道我应该使用一个只有输入ID的元素,并使用document.getElementById();打电话给该ID,但我不知道该怎么做。

在此先感谢!

+2

我们需要'Person'函数声明 –

回答

1

可以设置元素的innerHTML或者它的价值,如果它是一个输入端

相关问题