JS ----- JS实用小功能

1、复制页面上文字功能

   function copyIdCode()
    {
        var idcode = document.getElementById("personIdcodeCopy").innerText;
        var oInput = document.createElement('input');
        oInput.value = idcode;
        document.body.appendChild(oInput);
        oInput.select(); // 选择对象
        document.execCommand("Copy"); // 执行浏览器复制命令
        oInput.className = 'oInput';
        oInput.style.display = 'none';
        alert('复制成功');
    }



<p>身份证号码:<span id='personIdcodeCopy'>421023165465465498</span>   <a  onClick='copyIdCode()' class='value' style='color:blue;margin:20px;cursor: pointer;'>复制</a></p>

 

2、处理C#日期中的ticks 

      附件中存的是时间的ticks,在js中转成时间  new Date(parseInt((sttachmentsName[0]-621355968000000000)/10000))

      因为ticks不是时间戳,不能直接用  new Date(parseInt(时间戳))

var detail = "";
            var attachmentsArrys = rowdata.Attachments.split('|');
            for (var i = 0; i < attachmentsArrys.length; i++)
            {
                var sttachmentsName = attachmentsArrys[i].split('_');

                var url = "../upload/PassportRenewal/" + new Date(parseInt((sttachmentsName[0]-621355968000000000)/10000)).getFullYear() + "/" + attachmentsArrys[i];
                if (detail == "") {
                    detail = "<a href='" + url + "'  target='_blank'>" + sttachmentsName[1] + "</a>";
                }else
                {
                    detail = detail + "|" + "<a href='" + url + "'  target='_blank'>" + sttachmentsName[1] + "</a>";
                }

            }
            return detail;

 

 

3. 弹框居中

  DirectorGeneralUploadDiv为弹框的DIV的id   在显示之前调用一下这个方法

function scroll()
        {
            var a = $j(window).height();    //浏览器窗口高度
            var c = $j("#DirectorGeneralUploadDiv").offset().top;    //元素距离文档(document)顶部的高度
            if (c > a) {
                $j('html,body').animate({ scrollTop: $j('#DirectorGeneralUploadDiv').offset().top }, 800);
            }
        }

 

4、页面滑动到指定的位置

      在指位置加一个标签,调用scrollIntoView方法

 <span id='fk_span'></span>

function scroll(){
    document.getElementById("fk_span").scrollIntoView();
}

 

 

     

posted @ 2021-07-24 17:41  爱生活,爱代码  阅读(170)  评论(0编辑  收藏  举报