thinkphp查询出来的数组
控制器代码
$income = Db::name('table')->select();$this->assign('income',$income);
javascript代码
var arr = {:json_encode($income)};var total = new Array();var date = new Array();for(i=0;i<arr.length;i++){total.push(arr[i].total);date.push(arr[i].months);}
arr数组
total数组
date数组
thinkphp查找出来的数组进行遍历
{foreach $income as $v}<td class="total">{$v.total}</td>{/foreach}
划重点 标签要用class不能用id
<script>var arr = new Array();$(".total").each(function(){arr.push($(this).text());});console.log(arr);</script>
这样就可以将class为total的标签的值全部放到 arr数组中了
在控制台打印就可以看到arr数组中存的值了