html(1)新建一个构造对象:一个小组共有5个学生,每个学生都有属性(name,sex,address); (2)新建5个学生对象,学生的属性值,同学们自己任意的构造; 在网页的body中输出这5个学生的信息
时间: 2023-04-02 09:04:13 浏览: 73
(1) 请问您需要我回答的是关于编程的问题吗?
(2) 如果是的话,我可以帮您回答这个问题。首先,您可以使用 JavaScript 来创建一个构造函数,如下所示:
function Student(name, sex, address) {
this.name = name;
this.sex = sex;
this.address = address;
}
(3) 接下来,您可以使用该构造函数来创建 5 个学生对象,并为每个学生对象设置属性值,如下所示:
var student1 = new Student("张三", "男", "北京市");
var student2 = new Student("李四", "女", "上海市");
var student3 = new Student("王五", "男", "广州市");
var student4 = new Student("赵六", "女", "深圳市");
var student5 = new Student("钱七", "男", "成都市");
(4) 最后,您可以使用 JavaScript 将这 5 个学生对象的信息输出到网页的 body 中,如下所示:
document.body.innerHTML = "学生1:" + student1.name + "," + student1.sex + "," + student1.address + "<br>" +
"学生2:" + student2.name + "," + student2.sex + "," + student2.address + "<br>" +
"学生3:" + student3.name + "," + student3.sex + "," + student3.address + "<br>" +
"学生4:" + student4.name + "," + student4.sex + "," + student4.address + "<br>" +
"学生5:" + student5.name + "," + student5.sex + "," + student5.address;
阅读全文