扫码关注官方订阅号
$traffic$ $buynum$人购买 ¥$cost$现金券$discount$折 ¥$price$ $resname$
$traffic$
$buynum$人购买
¥$cost$现金券$discount$折
光阴似箭催人老,日月如移越少年。
$('textarea').val()
并没有 ul
ul
已经改好。弱弱问句把 String.prototype.temp = function(obj) 改成temp=function(obj) 怎么就不行了?
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title></title> <link rel="stylesheet" href=""> </head> <body> <ul> <li> <p>$loan_limited$</p> <p>$load_no$</p> <p>$payed$</p> <p>$amount$</p> <p>$loan_time$</p> </li> </ul> </body> <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js" type="text/javascript" charset="utf-8" ></script> <script type="text/javascript" charset="utf-8" > var data='[{"status": "IN_PROGRESS", "loan_limited": "5个月", "load_no": "123131231", "payed": "1个月", "amount": 15000, "loan_time": "2016-06-17"}, {"status": "DONE", "loan_limited": "1个月", "load_no": "123131123131231", "payed": "1个月", "amount": 15000, "loan_time": "2016-05-17"}, {"status": "IN_PROGRESS", "loan_limited": "5个月", "load_no": "123131231231", "payed": "1个月", "amount": 25000, "loan_time": "2016-06-10"}]'; var dataJson=JSON.parse(data); //console.log(dataJson); String.prototype.temp = function(obj) { return this.replace(/\$\w+\$/gi, function(matchs) { var returns = obj[matchs.replace(/\$/g, "")]; return (returns + "") == "undefined"? "": returns; }); }; var htmlList = '' , htmlTemp = $("ul").html(); console.log(htmlTemp.temp(dataJson)); dataJson.forEach(function(item) { htmlList += htmlTemp.temp(item); }); $("ul").html(htmlList); </script> </html>
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
$('textarea').val()并没有
ul已经改好。弱弱问句把 String.prototype.temp = function(obj) 改成temp=function(obj) 怎么就不行了?