jquery常用实例
$("#returnTop").click(function ()
{ var speed=200;//滑动的速度 $('body,html').animate({ scrollTop: 0 }, speed); return false;
});
js判断手机还是电脑访问
<script type="text/javascript">if(window.location.toString().indexOf('pref=padindex') != -1){}else{if(/AppleWebKit.*Mobile/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))){if(window.location.href.indexOf("?mobile")<0){try{if(/Android|Windows Phone|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent))
{window.location.href="{:U('Mobile/index/index')}";}else if(/iPad/i.test(navigator.userAgent)){}else{}}catch(e){}}}}</script>
$.ajax跨域请求数据
服务器端
namespace Home\Controller;
use Think\Controller\RestController;
Class InfoController extends RestController {
public function rest() {
$trade = M("Trade");
$data = $trade->order('id desc')->limit(4)->select();
foreach($data as $k=>$v){
$data[$k]['time']=date('Y-m-d h:i',$v['create_time']);
}
echo $_GET['jsoncallback'] . "(".json_encode($data).")";
exit;
}
public function detail() {
$id=$_GET['id'];
$trade = M("Trade");
$data = $trade->where(array('id'=>$id))->find();
$data['time']=date('Y-m-d h:i',$data['create_time']);
echo $_GET['jsoncallback'] . "(".json_encode($data).")";
exit;
}
}
html页面端
$.ajax(
{
type:'get',
url : url,
dataType : 'jsonp',
jsonp:"jsoncallback",
success : function(data) {
var html='';
$.each('data',function(i,k){
html+='<div class="list clearfix fl"><a href="./detail.html?id='+data[i].id+'"><samp></samp><span class="opa8"></span><p class="tit">'+data[i].title+'</p></a></div>';
})
$(".case-list").append(html);
},
}
);
<script>
var a=window.location.href;
var id=a.split('=');
var url='http://www.weihom.com/index.php/home/info/detail/id/'+id[1];
$.ajax(
{
type:'get',
url : url,
dataType : 'jsonp',
jsonp:"jsoncallback",
success : function(data) {
$(".lsf_title").html("<b>"+data.title+"</b>");
$(".lsf_time").html(data.time);
$(".nr").html(data.content);
$("title").html(data.title);
},
}
);
var a=window.location.href;
var id=a.split('=');
var url='http://www.weihom.com/index.php/home/info/detail/id/'+id[1];
$.ajax(
{
type:'get',
url : url,
dataType : 'jsonp',
jsonp:"jsoncallback",
success : function(data) {
$(".lsf_title").html("<b>"+data.title+"</b>");
$(".lsf_time").html(data.time);
$(".nr").html(data.content);
$("title").html(data.title);
},
}
);