js,jQuery脚本收藏

  1.获取滚动条位置:

    

//滚动条位置
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,  w, height: h };
    }

基本内容:

//在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 弹出警告窗口

$(function () {
            $('#divUploadDoc').dialog({
                autoOpen: false,
                 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数据

//获取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 根据缩略图弹出大图

//.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;100%;height:100%;position:absolute;top:0;right:0;" />');
            var bigImgDiv = $('<div id="bigImgDiv" style="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="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="100%" />').attr('src', $(this).attr('src'));
            bigImgDiv.append(bigImg);
            backgroudDiv.append(bigImgDiv);
            $('body').append(backgroudDiv);
            $('#closeButton').click(function () {
                $('#backgroundDiv').remove();
            });
        });
    </script>

 5、Js关闭页面(针对IE)

////关闭页面--要弹出提示(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         } 
Js代码
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" />
html代码

 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     }
View Code
原文地址:https://www.cnblogs.com/ganqiyin/p/3115745.html