-------------------------------------------------angular <scrinpt代码>----------------------------------------------------
<script>
var app=angular.module("yong",[]);app.controller("jiaong",function($scope,$http){
$http.get("http://result.eolinker.com/lKgJQ8Zec38423e5603b8e055d1193a8127c0c060bb1b55?uri=goodstest").success(function(a){
$scope.datas=a
});
//批量删除
$scope.delAll=function(){
var f=0;
for(var i=0;i<$scope.datas.length;i++){
if ($scope.datas[i].ck && $scope.datas[i].state=='未发货'){
$scope.datas.splice(i,1);
i--;
}
}
}
$scope.gb=function(){
//全选
for(var i=0;i<$scope.datas.length;i++){
$scope.datas[i].ck=$scope.ck;
//
}
}
/*//点击查询按钮开始查询
$scope.sel=function(){
$scope.sname1=$scope.sname;
$scope.stel1=$scope.stel;
$scope.ss1=$scope.ss;*/
//添加
$scope.save=function(){
$scope.erros=null;
if($scope.id==undefined||$scope.id==""){
if($scope.erros==null){
$scope.erros={};
}
$scope.erros.e_id="id不能为空";
}
if($scope.gname==undefined||$scope.gname==""){
if($scope.erros==null){
$scope.erros={};
}
$scope.erros.e_gname="商品名不能为空";
}
if($scope.uname==undefined||$scope.uname==""){
if($scope.erros==null){
$scope.erros={};
}
$scope.erros.e_uname="用户名不能为空";
}
if($scope.tel==undefined||$scope.tel==""){
if($scope.erros==null){
$scope.erros={};
}
$scope.erros.e_tel="电话不能为空";
}
if($scope.price==undefined||$scope.price==""){
if($scope.erros==null){
$scope.erros={};
}
$scope.erros.e_price="价格不能为空";
}
//是否输入都正确
if($scope.erros==null){
$scope.datas.push(
{"id":$scope.id,"gname":$scope.gname,"uname":$scope.uname,
"tel":$scope.tel,"price":$scope.price,
"provice":$scope.pro,"city":$scope.city,
"regdate":new Date(),"state":"未发货"});
$scope.isshow=false;
}
}
})
</script>
==============================html代码 ==============================
<body ng-app="yong" ng-controller="jiaong">
<input ng-model="sname" placeholder="请输入商品名称"/>
<input ng-model="name" placeholder="请输入用户姓名" />
<select ng-model="ss">
<option value="">--按状态查询--</option>
<option>已发货</option>
<option>未发货</option>
</select>
<!--<button ng-click="sel()">搜索</button>-->
<button ng-click="delAll()">批量删除</button>
<button ng-click="isshow=true">新增订单</button>
<table border="1px">
<tr align="center">
<td><input type="checkbox" ng-model="ck" ng-click="gb()"/></td>
<td>id <button ng-click="px='id';sj!=sj">排序</button></td>
<td>商品名称</td>
<td>用户姓名</td>
<td>电话</td>
<td>价格 <button ng-click="px='price';sj!=sj">排序</button></td>
<td>城市</td>
<td>下单时间</td>
<td>发货状态</td>
</tr>
<tr ng-repeat="d in datas|filter:{gname:sname,uname:name,state:ss}|orderBy:px:sj" align="center">
<td><input type="checkbox" ng-model="d.ck"/></td>
<td>{{d.id}}</td>
<td>{{d.gname}}</td>
<td>{{d.uname}}</td>
<td>{{d.tel}}</td>
<td>{{d.price|currency:"¥"}}</td>
<td>{{d.provice}}-{{d.city}}</td>
<td>{{d.regdate|date:'MM-dd hh:mm:ss'}}</td>
<td>
<span style="background: yellow;" ng-show="d.state=='未发货'">
<a href="#" ng-click="d.state='已发货'">未发货</a>
</span>
<span style="background: chartreuse;" ng-show="d.state=='已发货'" >已发货</span>
</td>
</tr>
</table>
//添加
<form ng-show="isshow">
<!--{{erros}}<br/>-->
id:<input ng-model="id" /> <samp style="color: red;">{{erros.e_id}} </samp><br />
gname:<input ng-model="gname" /><samp style="color: red;">{{erros.e_gname}}</samp><br />
uname:<input ng-model="uname" /><samp style="color: red;">{{erros.e_uname}}</samp><br />
tel:<input ng-model="tel" /><samp style="color: red;">{{erros.e_tel}}</samp><br />
price:<input ng-model="price" type="number" /><samp style="color: red;">{{erros.e_price}}</samp><br />
省:<select id="p" ng-model="pro" οnchange="getcity()"> <!--ng-modle 双向绑定 视图改变对应的变量pro -->
<option value="">请选择省份</option>
<option>北京</option>
<option>上海</option>
<option>河南</option>
</select>
<br/>
城市:
<select id="city" ng-model="city" > <!--ng-modle 双向绑定 视图改变对应的变量pro -->
<option value="">请选择城市</option>
</select>
<br/>
<button ng-click="save()">保存</button>
</form>
</body>
----------------------------------------------jquery<script>代码--------------------------------------------------------
<script>
var ds=[{"pro":'北京',citys:['海淀','朝阳','昌平']},
{"pro":'上海',citys:['浦东','浦西']},
{"pro":'河南',citys:['郑州','安阳','濮阳']}
];
function getcity(){
var p=$("#p").val();
var cs=[];
//根据省 获取对应的城市
for(var i=0;i<ds.length;i++){
if(p==ds[i].pro){
cs=ds[i].citys;
}
}
//先删除
$("#city option").remove();
//循环cs,添加option到select中
for(var i=0;i<cs.length;i++){
var op=$("<option>"+cs[i]+"</option>")
//把optoin添加到select
$("#city").append(op);
}
}
</script>
//效果图1:
//效果图2: