小编Cor*_*lly的帖子

将值从输入传递给返回对象的构造函数

目标:我试图将值从输入传递给返回对象的构造函数

问题:我得到的所有回报都是“未定义”,我认为这可能与我的按钮上的 onclick 有关,也许我没有正确调用它。我真的不确定。我在互联网上找遍了都找不到答案。

JavaScript

var name = document.getElementById('inputValueName').value;
var age = document.getElementById('inputValueAge').value;
var state = document.getElementById('inputValueState').value;

function person(name, age, state) {
    this.name = name;
    this.age = age;
    this.state = state;
}
var NewPerson = new person(name, age, state);

console.log(NewPerson);
Run Code Online (Sandbox Code Playgroud)

HTML

<input type="text" id="inputValueName">
<input type="text" id="inputValueAge">
<input type="text" id="inputValueState">
<button id="btn" onclick="person();">Add</button>
Run Code Online (Sandbox Code Playgroud)

javascript oop

1
推荐指数
1
解决办法
455
查看次数

标签 统计

javascript ×1

oop ×1