百度搜索功能

<!DOCTYPE html>
<html lang="en" ng-app="myApp">
<head>
 <meta charset="UTF-8">
 <title>百度搜索</title>
 <script src="js/angular.min.js"></script>
 <script>
  var m1=angular.module('myApp',[])
  m1.controller('myCtrl',['$scope','$timeout','$http',function($scope,$timeout,$http){
   $scope.search=function(str){
    $timeout.cancel(timer)
    var timer=$timeout(function(){
     $http({
      method:'JSONP',
      url:'https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?wd='+str+'&cb=JSON_CALLBACK',
     }).success(function(data){
      console.log(data)
      $scope.dataList=data.s
     })
    },200)
   }
  }])
 </script>
</head>
<body>
 <div ng-controller="myCtrl">
  <input type="text" ng-model="searchVal" ng-change="search(searchVal)">
  <input type="button" ng-click="search(searchVal)" value="搜索">
  <ul>
   <li ng-repeat="data in dataList">{{data}}</li>
  </ul>
 </div>
</body>
</html>

posted on 2017-07-11 23:03  就爱水溶C  阅读(177)  评论(0编辑  收藏  举报

导航