html计算商品价格,使用Per.js快速开发商品价格计算页面 - for Per.js3.0

先预览一下全部代码:

Per.js Demo

Welcome to use this price calculation!

  • This is {{var1.name}}
  • The price is: {{var1.price}} - To expensive!

to page1

to page2

Refresh

Per.use("Per.page");

Per.page.create.pageGroup("allPage");

Per.page.create.page("allPage","#page1");

Per.page.create.page("allPage","#page2");

var app = Per("ul");

app.dom({

loop: [{name: "apple",price: 20},{name: "bread",price: 30},{name: "banana",price: 25}],

callback: function(){

Per("span").dom({

con: "in"

});

}

},true,true);

Per("#btn-refre").dom({

info: {

item: [{name: "apple",price: 20},{name: "bread",price: 30},{name: "banana",price: 25}]

},

click: function(){

this._super.innerHTML = "Refresh now!";

var val = parseInt(Math.random()*30+1);

this.item[0].price = val;

val = parseInt(Math.random()*30+1);

this.item[1].price = val;

val = parseInt(Math.random()*30+1);

this.item[2].price = val;

app.dom.loop = this.item;

}

});

Per("#tp1").dom({

click: function(){

Per.page.to("allPage",1);

}

});

Per("#tp2").dom({

click: function(){

Per.page.to("allPage",2);

}

});

然后发上一波效果图:

25b5b96bb8d0c4682f35a8bfe926b75e.png

没错,就是这样一个页面,那么接下来我就来教大家如何制作。

先把基本页面格式写好。

Per.js Demo

之后我们使用script标签来引入Per.js文件:

再然后,我们在body标签里面写上基本结构:

Welcome to use this price calculation!

  • This is {{var1.name}}
  • The price is: {{var1.price}} - To expensive!

to page1

to page2

Refresh

之后在script标签里面再写js语句:

Per.use("Per.page");

Per.page.create.pageGroup("allPage");

Per.page.create.page("allPage","#page1");

Per.page.create.page("allPage","#page2");

var app = Per("ul");

app.dom({

loop: [{name: "apple",price: 20},{name: "bread",price: 30},{name: "banana",price: 25}],

callback: function(){

Per("span").dom({

con: "in"

});

}

},true,true);

Per("#btn-refre").dom({

info: {

item: [{name: "apple",price: 20},{name: "bread",price: 30},{name: "banana",price: 25}]

},

click: function(){

this._super.innerHTML = "Refresh now!";

var val = parseInt(Math.random()*30+1);

this.item[0].price = val;

val = parseInt(Math.random()*30+1);

this.item[1].price = val;

val = parseInt(Math.random()*30+1);

this.item[2].price = val;

app.dom.loop = this.item;

}

});

Per("#tp1").dom({

click: function(){

Per.page.to("allPage",1);

}

});

Per("#tp2").dom({

click: function(){

Per.page.to("allPage",2);

}

});

之后打开浏览器,就正常执行了!

效果如同上方gif图一样!

【tips:必须使用Per.js >= 3.0版本】

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值