仿写电话簿

HTML

姓名: 电话号码:
姓名:
姓名: 电话号码:

css

li{
    list-style: none;
    overflow: hidden;
}
li div{
    width: 150px;
    float: left;
}

JS

构造函数写法
var data = [{name:"李娜",phone:"15866936545",{name:"king",phone:"15869253647"}];
function PhoneBook(data){
            this.data = data;
        }
        //呈现数据的方法
        PhoneBook.prototype.showData = function(){
            var html = '';
            for(let i = 0;i
"+this.data[i].phone+"
"; } document.getElementsByTagName("ul")[0].innerHTML=html; } PhoneBook.prototype.addData = function(name,phone){ var obj={name,phone} this.data.push(obj); } PhoneBook.prototype.searchData = function(name){ for(let i=0;i
类的方法
var data = [{name:"李娜",phone:"15866936545"},{name:"king",phone:"15869253647"}];
class PhoneBook{
            constructor(data){
                this.data = data;
            }
            showData(){
                    var html = '';
                for(let i = 0;i
"+this.data[i].phone+"
"; } document.getElementsByTagName("ul")[0].innerHTML=html; } addData(name,phone){ var obj={name,phone} this.data.push(obj); } searchData(name){ for(let i=0;i

写的不好,希望大家多多指点

你可能感兴趣的:(仿写电话簿)