修改为form表单

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script src="js/angular.js"></script>
<script src="js/jquery-3.2.1.min.js"></script>
<script>
  
var app=angular.module("Liu",[]);
app.controller("myApp",function($scope,$http){
 $scope.jsonFromeNet="";
 //准备数据
 $http({
   method:"get",
   url:"http://gank.io/api/data/Android/10/1"
 }).then(
  function success(response){
     $scope.jsonFromeNet=response.data;
    },function error(response){
 
        }
 );
    
    //删除数据
    $scope.dele=function($index){
    $scope.jsonFromeNet.results.splice($index,1);
   
    }     
    $scope.ifFlag=false;
        
    //添加数据
    $scope.addnew=function(){
    $scope.ifFlag=!$scope.ifFlag;    
    }
    $scope.newtype="";
    $scope.newsource="";
    $scope.newcreatedAt="";
    $scope.newwho="";
        
    $scope.addGood=function(){
    if($("#but01").val()=="添加"){
    var good={
    type:$scope.newtype,
    source:$scope.newsource,
    createdAt:$scope.newcreatedAt,
    who:$scope.newwho,    
    };
    $scope.jsonFromeNet.results.push(good);
    $scope.ifFlag=false;    
    }    
    }
    $scope.updete=0;
    //修改商品
     $scope.ifFlag1=false;
     $scope.sele=function($index){
      $scope.ifFlag1=!$scope.ifFlag1;
          $scope.newtype=$scope.jsonFromeNet.results[$index].type;
          $scope.newsource=$scope.jsonFromeNet.results[$index].source;
          $scope.newcreatedAt=$scope.jsonFromeNet.results[$index].createdAt;
          $scope.newwho=$scope.jsonFromeNet.results[$index].who;
            $scope.indexs=$index;            
     }
     $scope.seleGood=function(){
         $scope.jsonFromeNet.results[ $scope.indexs].type=$scope.newtype;
         $scope.jsonFromeNet.results[ $scope.indexs].source=$scope.newsource;
         $scope.jsonFromeNet.results[ $scope.indexs].createdAt=$scope.newcreatedAt;
         $scope.jsonFromeNet.results[ $scope.indexs].who=$scope.newwho;          
         $scope.ifFlag1=false;
     }  
 $scope.search="";
 $scope.px="";
});  
</script>
<style>
.table{
width: 600px;
height: 30px;
margin: 0 auto;
}
</style>
</head>
<body ng-app="Liu" ng-controller="myApp">
   <center>
    <h3>IT权威新闻</h3>
    <input type="text" placeholder="请输入查询关键字" ng-model="search"/>
    <select ng-model="px">
    <option value="" selected="selected">--请选择--</option>
    <option value="createdAt">按时间升序</option>
    <option value="-createdAt">按时间降序</option>
    </select>
    <input type="button" value="添加新闻" ng-click="addnew()"/><br /><br />
     <table border="1" cellspacing="0" class="table">
      <tr>
               <th>序号</th>
      <th>type</th>
      <th>source</th>
      <th ng-click="px='createdAt'">createdAt</th>
      <th>who</th>
      <th>操作</th>
      </tr>
      <tr ng-repeat="g in jsonFromeNet.results | orderBy:px| filter:search ">
      <td>{{$index+1}}</td>
      <td>{{g.type}}</td>
      <td>{{g.source}}</td>
      <td>{{g.createdAt | date:"yyyy-MM-dd hh:mm:ss"}}</td>
      <td>{{g.who}}</td>
      <td>
      <input type="button" ng-click="dele($index)" value="删除"/>
      <input type="button" ng-click="sele($index)" value="修改"/>      
      </td>
      </tr>
     </table>      
     <div ng-show="ifFlag">
      <table style="text-align: center; width: 270px; height: 100px;">
      <tr style="text-align: right;">
      <td>type:<input type="text" ng-model="newtype"/><br /></td>
      </tr>
      <tr style="text-align: right;">
      <td>source:<input type="text" ng-model="newsource"/><br /></td>
      </tr>
      <tr style="text-align: right;">
      <td>createdAt:<input type="text" ng-model="newcreatedAt"/><br /></td>
      </tr>
      <tr style="text-align: right;">
      <td>who:<input type="text" ng-model="newwho"/><br /></td>
      </tr>
      <tr>
      <td><input type="button" id="but01" value="添加" ng-click="addGood()"/></td>
      </tr>
      </table>
             </div>           
     <div ng-show="ifFlag1">
      <table style="text-align: center; width: 270px; height: 100px;">
      <tr style="text-align: right;">
      <td>type:<input type="text" ng-model="newtype"/><br /></td>
      </tr>
      <tr style="text-align: right;">
      <td>source:<input type="text" ng-model="newsource"/><br /></td>
      </tr>
      <tr style="text-align: right;">
      <td>createdAt:<input type="text" ng-model="newcreatedAt"/><br /></td>
      </tr>
      <tr style="text-align: right;">
      <td>who:<input type="text" ng-model="newwho"/><br /></td>
      </tr>
      <tr>
      <td><input type="button" id="but02" value="修改" ng-click="seleGood()"/></td>
      </tr>
      </table>
             </div>      
   </center>
</body>
</html>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值