html(1)新建一个构造对象:一个小组共有5个学生,每个学生都有属性(name,sex,address); (2)新建5个学生对象,学生的属性值,同学们自己任意的构造; (3)在网页的body中输出这5个学生的信息。
时间: 2023-04-02 17:04:12 浏览: 88
(1) 以下是创建学生对象的构造函数:
function Student(name, sex, address) {
this.name = name;
this.sex = sex;
this.address = address;
}
(2) 以下是创建5个学生对象的代码:
var student1 = new Student("张三", "男", "北京");
var student2 = new Student("李四", "女", "上海");
var student3 = new Student("王五", "男", "广州");
var student4 = new Student("赵六", "女", "深圳");
var student5 = new Student("钱七", "男", "成都");
(3) 以下是在网页的body中输出这5个学生的信息的代码:
document.body.innerHTML += "学生1:" + student1.name + ",性别:" + student1.sex + ",地址:" + student1.address + "<br>";
document.body.innerHTML += "学生2:" + student2.name + ",性别:" + student2.sex + ",地址:" + student2.address + "<br>";
document.body.innerHTML += "学生3:" + student3.name + ",性别:" + student3.sex + ",地址:" + student3.address + "<br>";
document.body.innerHTML += "学生4:" + student4.name + ",性别:" + student4.sex + ",地址:" + student4.address + "<br>";
document.body.innerHTML += "学生5:" + student5.name + ",性别:" + student5.sex + ",地址:" + student5.address + "<br>";
阅读全文
相关推荐
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![cpp](https://img-home.csdnimg.cn/images/20250102104920.png)
![cs](https://img-home.csdnimg.cn/images/20250102104920.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231045021.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044833.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)