[英]I don't see why my code isn't taking the value of the input box and making a new object
The code for this is at 这个代码是在
This is the Javascript : 这是Javascript:
document.getElementById("submit").onclick = function() {
function Person(fullname, job, country, city) {
this.fullname = fullname;
this.job = job;
this.country = country;
this.city = city;
}
var fullname = document.getElementById("fname").value;
var job = document.getElementById("job").value;
var country = document.getElementById("country").value;
var city = document.getElementById("city").value;
var me = new Person(fullname, job, country, city);
document.getElementById("p").innerHTML = me.fullname + ". Congratulations an object has been made with your information stored in it, the following information is what you have given us. Your job is a " + me.job + "You live in" + me.city + "," + me.country + ".";
};
This is the HTML: 这是HTML:
<body>
<div>
<input type="text" id="fname" placeholder ="Full Name" name="fullname">
<input type="text" id="job" placeholder ="Job" name="job">
<input type="text" id="country" placeholder ="Country" name="country">
<input type="text" id="city" placeholder ="City" name="city">
<input type="submit" value="Submit">
<p id="p1"></p>
</div>
</body>
document.querySelector('input[type="submit"]')
; 提交按钮上没有id使用document.querySelector('input[type="submit"]')
; instead. 代替。 <p>
is p1
<p>
的id是p1
<!doctype html> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> </head> <body> <div> <input type="text" id="fname" placeholder ="Full Name" name="fullname"> <input type="text" id="job" placeholder ="Job" name="job"> <input type="text" id="country" placeholder ="Country" name="country"> <input type="text" id="city" placeholder ="City" name="city"> <input type="submit" value="Submit"> <p id="p1"></p> </div> <script> document.querySelector('input[type="submit"]').onclick = function() { function Person(fullname, job, country, city) { this.fullname = fullname; this.job = job; this.country = country; this.city = city; } var fullname = document.getElementById("fname").value; var job = document.getElementById("job").value; var country = document.getElementById("country").value; var city = document.getElementById("city").value; var me = new Person(fullname, job, country, city); document.getElementById("p1").innerHTML = me.fullname + ". Congratulations an object has been made with your information stored in it, the following information is what you have given us. Your job is a " + me.job + "You live in" + me.city + "," + me.country + "."; }; </script> </body> </html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.