JQ笔记-----

来源:互联网 发布:手机本地端口1080 编辑:程序博客网 时间:2024/06/05 10:59
<pre name="code" class="javascript">alert($(window).height()); //浏览器时下窗口可视区域高度alert($(document).height()); //浏览器时下窗口文档的高度alert($(document.body).height());//浏览器时下窗口文档body的高度alert($(document.body).outerHeight(true));//浏览器时下窗口文档body的总高度 包括border padding marginalert($(window).width()); //浏览器时下窗口可视区域宽度alert($(document).width());//浏览器时下窗口文档对于象宽度alert($(document.body).width());//浏览器时下窗口文档body的高度alert($(document.body).outerWidth(true));//浏览器时下窗口文档body的总宽度 包括border padding marginalert($(document).scrollTop()); //获取滚动条到顶部的垂直高度alert($(document).scrollLeft()); //获取滚动条到左边的垂直宽度//控制字符长度兼容 function wordList(obj,num){   obj.each(function(){ var maxwidth=num; if($(this).text().length>maxwidth){ $(this).text($(this).text().substring(0,maxwidth)); $(this).html($(this).html()+'....'); }  });   }   判断IE版本 if(navigator.userAgent.indexOf("MSIE")>0){         if(navigator.userAgent.indexOf("MSIE 6.0")>0){           alert("ie6");          }         if(navigator.userAgent.indexOf("MSIE 7.0")>0){          alert("ie7");         }         if(navigator.userAgent.indexOf("MSIE 9.0")>0 && !window.innerWidth){//这里是重点,你懂的        alert("ie8");        }         if(navigator.userAgent.indexOf("MSIE 9.0")>0){          alert("ie9");        }       }  判断浏览器类型<script language="JavaScript"><!--function getOs(){var OsObject = "";if(navigator.userAgent.indexOf("MSIE")>0) {return "MSIE";}if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){return "Firefox";}if(isSafari=navigator.userAgent.indexOf("Safari")>0) {return "Safari";}if(isCamino=navigator.userAgent.indexOf("Camino")>0){return "Camino";}if(isMozilla=navigator.userAgent.indexOf("Gecko/")>0){return "Gecko";}}//全选(obj  是改input的id或class)function SelectAllRows(obj) { var sbvalue=$(obj)[0].value; var check_obj = $("input[name='checkItem']"); for (var i = 0; i < check_obj.length; i++) { if(sbvalue!=null&&sbvalue=='全部选择') { check_obj.get(i).checked = true; $(obj)[0].value='取消全选'; } else if(sbvalue!=null&&sbvalue=='取消全选') { check_obj.get(i).checked = false; $(obj)[0].value='全部选择'; } }}//视频兼容function videos(video){if(navigator.userAgent.indexOf("MSIE")>0){ $("#videoM").append('<object classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95" width="644" height="428" >'+ '<param name="Filename" value='+video+'>'+ '<param name="PlayCount" value="0">'+ '<param name="AutoStart" value="0">'+ '<param name="ClickToPlay" value="1">'+ '<param name="EnableFullScreen Controls" value="1">'+ '<param name="ShowAudio Controls" value="1">'+'<param name="EnableContext Menu" value="1">'+ '<param name="ShowDisplay" value="0">'+ '</object>'); }else{ $("#videoM").append('<video controls width="644px" height="428px">'+ '<source src='+video+' type="video/mp4"></source>'+ '<source src='+video+' type="video/ogg"></source>'+ '</video>'); } }//删除选中 (结合后台删除购物车)$("#delSelect").click(function(){var checked_num = $("input[name='checkItem']:checked").length;if (checked_num == 0) {alert("至少选择一项");return;}//多项选择后的操作代码var idList = "";if(confirm( "确定要删除?" )){var check_obj = $("input[name='checkItem']");for (var i = 0; i < check_obj.length; i++) {if(check_obj.get(i).checked == true){idList+=check_obj.get(i).value+",";}}idList = idList.substring(0, idList.length - 1);var method="${webHost}${orgId}/removeSelect.do";var datas={'product':idList};private_ajax(method,datas,function(data){window.location.href="${webHost}${orgId}/cart.do";});}});==============后台代码//删除选中@RequestMapping(value = "{orgId}/removeSelect")@ResponseBodypublic String removeSelect(@PathVariable String orgId, HttpSession session,CartVo cart, HttpServletRequest request){if (session.getAttribute(orgId + "_cart") != null) {String items = request.getParameter("product");String[] item = items.split(",");List<String> l=Arrays.asList(item);@SuppressWarnings("unchecked")List<CartVo> list = (List<CartVo>) session.getAttribute(orgId+ "_cart");//session获取购物车的内容 session.removeAttribute(orgId + "_cart");//这个直接清空购物车 String productAtrr=""; //要倒写循环才有用  for (int i = list.size()-1; i >= 0; i--)  { CartVo vo= list.get(i); productAtrr=vo.getProductId()+vo.getSize()+vo.getColor()+vo.getModel(); if(l.toString().contains(productAtrr)){ list.remove(vo); } } session.setAttribute(orgId + "_cart", list); }return "removeSelect";}//其他的就直接结合根据ID删除即可、、//滚动条的滑动距离大于等于定位元素距离浏览器顶部的距离s$(function(){//获取要定位元素距离浏览器顶部的距离var navH = $("#navTop").offset().top;//滚动条事件$(window).scroll(function(){//获取滚动条的滑动距离var scroH = $(this).scrollTop();//滚动条的滑动距离大于等于定位元素距离浏览器顶部的距离,就固定,反之就不固定if(scroH>=navH ){$("#navTop").css({"position":"fixed","top":0,"z-index":9999,"Left":0});$("#Classification").hover(function(){$("#dn").css({display:"block"})},function(){$("#dn").css({display:"none"})});$("#dn").hover(function(){$(this).css({display:"block"})},function(){$(this).css({display:"none"})});}else if(scroH<navH){$("#navTop").css({"position":"static"});} }); )};



0 0
原创粉丝点击