【发布时间】:2021-04-25 15:09:20
【问题描述】:
我目前正在尝试在 html 中显示我的对象和方法。我的目标是在 html 中有 2 个按钮(info vacc1,info vacc2,打印我的对象的信息。我的目标是在我的按钮下方输出它
这是我的 js 代码:
function myVaccines(companyName, vaccName, Type, numberOfShots, doesNotContain){
this.companyName = companyName;
this.vaccName = vaccName;
this.Type = Type;
this.numberOfShots = numberOfShots;
this.doesNotContain = doesNotContain;
}
var vacc1 = Vacc("Pfizer-BioNTech","BNT162b2","mRNA","2 shots, 21 days apart","Eggs, Preservatives, Latex");
var vacc2 = Vacc("Moderna","mRNA-1273","mRNA","2shots, 28 days apart","Eggs, Preservatives, Latex",)
这是我的 html:(还不知道该放什么)
<button onclick="myVaccines(vacc1)">
Information Vaccine 1
</button>
<p>Output1?</p>
<button onclick="myVaccines(vacc2)">
Information Vaccine 2
</button>
<p>Output2?</p>
【问题讨论】:
标签: javascript html methods javascript-objects