angularjs实现百度的搜索接口及链接的实现

angularjs实现百度的搜索接口及链接功能

<!DOCTYPE html>
<html ng-app="myApp">
	<head>
		<meta charset="UTF-8">
		<title>搜索</title>
		<style>
			*{
				margin:0;
				padding:0;
			}
			#wei{
				width:500px;
				height:600px;
				margin:0 auto;
				border:0px solid gray;
			}
			#wei input{
					width:476px;
					height:50px;
					line-height: 50px;
					padding-left:20px;
					font-size: 16px;
			}
			#wei ul {
				height:auto;
				border:1px solid #ccc;
			}
			#wei ul li{
					width:100%;
					height:30px;
					line-height: 30px;
					text-indent:10px;
					font-size: 16px;
					list-style: none;
			}
			#wei ul li a{
					text-decoration:none;
			}
			#wei ul li:hover{
				display:block;
				background:#ccc;
				color:#fff;
			}
		</style>
	</head>
	<body ng-controller="show">
			<div id="wei">
				<input type="text" ng-model="data" ng-keyup="change(data)" >
				<ul><!-- 添加链接 -->
					<li ng-repeat="attr in arr"><a href="https://www.baidu.com/s?wd={{attr}}">{{attr}}</a></li>
				</ul>
			</div>
		<script src="angular.min.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			var app = angular.module('myApp',[]);
			app.controller('show',['$scope','$http',function($scope,$http){
				$scope.arr=[];
				$scope.change = function(data){
					//进行请求
					$http({
						"method":"jsonp",
						"url":"https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?wd="+$scope.data+"&cb=JSON_CALLBACK"
						//回调函数必须为JSON_CALLBACK,百度默认的
					}).success(function(res){//数据请求成功时返回数据
						$scope.arr=res.s;
					})
					}
			}]);
		</script>	
	</body>
</html>


  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值