js,jQuery脚本收藏
1.获取滚动条位置:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | //滚动条位置 function ScollPostion() { var t, l, w, h; if (document.documentElement && document.documentElement.scrollTop) { t = document.documentElement.scrollTop; l = document.documentElement.scrollLeft; w = document.documentElement.scrollWidth; h = document.documentElement.scrollHeight; } else if (document.body) { t = document.body.scrollTop; l = document.body.scrollLeft; w = document.body.scrollWidth; h = document.body.scrollHeight; } return { top: t, left: l, width: w, height: h }; } |
基本内容:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | //在IE中: document.body.clientWidth ==> BODY对象宽度 document.body.clientHeight ==> BODY对象高度 document.documentElement.clientWidth ==> 可见区域宽度 document.documentElement.clientHeight ==> 可见区域高度 //在FireFox中: document.body.clientWidth ==> BODY对象宽度 document.body.clientHeight ==> BODY对象高度 document.documentElement.clientWidth ==> 可见区域宽度 document.documentElement.clientHeight ==> 可见区域高度? //在Opera中: document.body.clientWidth ==> 可见区域宽度 document.body.clientHeight ==> 可见区域高度 document.documentElement.clientWidth ==> 页面对象宽度(即BODY对象宽度加上Margin宽) document.documentElement.clientHeight ==> 页面对象高度(即BODY对象高度加上Margin高) //而如果没有定义W3C的标准,则 //IE为: document.documentElement.clientWidth ==> 0 document.documentElement.clientHeight ==> 0 //FireFox为: document.documentElement.clientWidth ==> 页面对象宽度(即BODY对象宽度加上Margin宽)document.documentElement.clientHeight ==> 页面对象高度(即BODY对象高度加上Margin高) //Opera为: document.documentElement.clientWidth ==> 页面对象宽度(即BODY对象宽度加上Margin宽)document.documentElement.clientHeight ==> 页面对象高度(即BODY对象高度加上Margin高) //真是一件麻烦事情,其实就开发来看,宁可少一些对象和方法,不使用最新的标准要方便许多啊。 ////////////////////////////////////////////////////////////////////////////////////// //网页可见区域宽: document.body.clientWidth //网页可见区域高: document.body.clientHeight //网页可见区域宽: document.body.offsetWidth(包括边线的宽) //网页可见区域高: document.body.offsetHeight(包括边线的宽) //网页正文全文宽: document.body.scrollWidth //网页正文全文高: document.body.scrollHeight //网页被卷去的高: document.body.scrollTop //网页被卷去的左: document.body.scrollLeft //网页正文部分上: window.screenTop //网页正文部分左: window.screenLeft //屏幕分辨率的高: window.screen.height //屏幕分辨率的宽: window.screen.width //屏幕可用工作区高度: window.screen.availHeight //屏幕可用工作区宽度: window.screen.availWidth |
2、jQuery 弹出警告窗口
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | $( function () { $( '#divUploadDoc' ).dialog({ autoOpen: false , width: 700, height: 600, open: function (type, data) { $( this ).parent().appendTo( "form:first" ); } }); // Dialog Link $( '.btnShowUpload' ).click( function () { $( '#divUploadDoc' ).dialog( 'open' ); return false ; }); $( '.btnShowUpload' ).click( function () { $( '#divUploadDoc' ).dialog( 'close' ); return false ; }); } |
3、JS获取 QueryString数据
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | //获取QueryString的数组 function getQueryString() { alert(location.search) var result = location.search.match( new RegExp( "[\?\&][^\?\&]+=[^\?\&]+" , "g" )); if (result == null ) { return "" ; } for ( var i = 0; i < result.length; i++) { result[i] = result[i].substring(1); } return result; } //根据QueryString参数名称获取值 function getQueryStringByName(name) { var result = location.search.match( new RegExp( "[\?\&]" + name + "=([^\&]+)" , "i" )); if (result == null || result.length < 1) { return "" ; } return result[1]; } //根据QueryString参数索引获取值 function getQueryStringByIndex(index) { if (index == null ) { return "" ; } var queryStringList = getQueryString(); if (index >= queryStringList.length) { return "" ; } var result = queryStringList[index]; var startIndex = result.indexOf( "=" ) + 1; result = result.substring(startIndex); return result; } |
4、JQuery 根据缩略图弹出大图
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | //.xxx_img 这个是 class <script type= "text/javascript" > $( '.xxx_img' ).unbind( 'click' ).click( function () { if ($( '#bigImgDiv' ).length != 0) { return ; } var backgroudDiv = $( '<div id="backgroundDiv" style="text-align: center;width:100%;height:100%;position:absolute;top:0;right:0;" />' ); var bigImgDiv = $( '<div id="bigImgDiv" style="width:50%;background-color:white;text-align:right;padding:5px;display:block;border:1px black solid;margin:200px auto;" />' ); bigImgDiv.html( '<a href="javascript:void(0)" style="width:100%;display:block;color:red;text-decoration:bode;font-size:2em;opacity:1.0;filter:alpha(opacity=100)" id="closeButton"><b>X</b></a>' ); var bigImg = $( '<img style="width:100%" />' ).attr( 'src' , $( this ).attr( 'src' )); bigImgDiv.append(bigImg); backgroudDiv.append(bigImgDiv); $( 'body' ).append(backgroudDiv); $( '#closeButton' ).click( function () { $( '#backgroundDiv' ).remove(); }); }); </script> |
5、Js关闭页面(针对IE)
1 2 3 4 5 6 7 | ////关闭页面--要弹出提示(IE6及以下不弹出提示) ClientScript.RegisterStartupScript(Page.GetType(), "" , "<script language=javascript>window.opener=null;window.close();</script>" ); Response.Write( "<script>window.close();</script>" ); // 会弹出询问是否关闭 //不弹出提示直接关闭页面 ClientScript.RegisterStartupScript(Page.GetType(), "" , "<script language=javascript>window.opener=null;window.open('','_self');window.close();</script>" ); |
6、JS 页面 打印

1 //打印 2 function PrintArticle() { 3 var pc = document.getElementById("<%=showPicDiv.ClientID%>"); 4 var pw = window.open('', '', 'width=1024,height=800'); 5 pw.document.write('<html>'); 6 pw.document.write('<head>'); 7 pw.document.write('<title>View Print Pictogram</title>'); 8 pw.document.write('</head>'); 9 pw.document.write('<body style="page-break-after:always;">'); 10 pw.document.write(pc.innerHTML); 11 pw.document.write('</body>'); 12 pw.document.write('</html>'); 13 pw.document.close(); 14 setTimeout(function () { 15 pw.print(); 16 }, 500); 17 return false; 18 }

1 //打印内容 2 <div id="showPicDiv" runat="server"> 3 打印内容 4 </div> 5 //打印按钮 6 <asp:Button ID="PrintButton" runat="server" OnClientClick="PrintArticle()" meta:resourcekey="PrintButton" Text="Pint Pictogram" />
7、验证输入的是不是数字

1 //验证是否是正整数 2 function isUnsignedInteger(a) { 3 var reg = /^\+?[1-9]\d*$/; //正整数 4 return reg.test(a); 5 }
8、获取请求参数

1 //获取Request 2 function GetRequest() { 3 var url = location.search; //获取url中"?"符后的字串 4 var theRequest = new Object(); 5 if (url.indexOf("?") != -1) { 6 var str = url.substr(1).toLocaleLowerCase(); 7 var strs = str.split("&"); 8 for (var i = 0; i < strs.length; i++) { 9 theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]); 10 } 11 12 } 13 return theRequest; 14 }
漫漫人生,唯有激流勇进,不畏艰险,奋力拼搏,方能中流击水,抵达光明的彼岸
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
· 【译】Visual Studio 中新的强大生产力特性
· 2025年我用 Compose 写了一个 Todo App