【发布时间】:2025-11-23 12:30:02
【问题描述】:
所以,我创建了一个 HTML 文件,其中包含带有以下标签的按钮:名字、姓氏等
我需要对按钮进行编程,以便当用户单击它时,拳头名称按钮应该消失,而在 <div> 中,您会看到名称“John Doe”
我在我的 .js 文件中创建了这个:
// create a JavaScript object here with the following fields: firstName, lastName, jobTitle, homeOffice
var demo = {
firstName : "Waseem",
lastName : "Qazi",
jobTitle : "Traveler Care",
homeOffice : "Penn. field",
tellMeMore : "Exicted to re-start my coding adventure again. Been a while
since I had coded. Looking forward to all the learning and growth this
amazing oppportunity will present."
givefirstname : function() {
return this.firstName;
};
使用 jQuery 和上面的对象,在单击相应按钮时显示信息。
如何在 HTML 文件中调用它,以便每个函数在屏幕上返回相应的数据?
我在 HTML 文件中的调用行:
<li>
<a class="selected" href="">
<button type="button" onclick=demo.givefirstname>
First Name
</button>
</a>
</li>
<br>
【问题讨论】:
-
你不能把
<button>放在<a>里面。见*.com/questions/6393827/… -
你说你想把名字放在
<div>里面。您的 HTML 中没有 DIV。
标签: javascript html object methods