码迷,mamicode.com
首页 > Web开发 > 详细

js 复制、全选功能

时间:2015-10-27 11:44:04      阅读:285      评论:0      收藏:0      [点我收藏+]

标签:

<%--
  Created by IntelliJ IDEA.
  User: admin
  Date: 2015/10/23
  Time: 16:24
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String inData = request.getAttribute("inData").toString();
%>
<%@ include file="/global/commonPage/includeHead/commonHead.jsp" %>
<%@ include file="/global/commonPage/includeHead/extHead.jsp" %>
<html>
<head>
    <title>数据详情</title>
    <script src="<%=baseUrl%>/global/js/jquery.json.js" ></script>
    <script src="<%=baseUrl%>/global/js/jquery.zclip.js" ></script>
    <script>
        $(document).ready(function(){
            var inData =‘<%=inData%>‘;
            formate2Json(inData);
        } );

        function formate2Json(data){
            var result = ‘‘;
            if(data != ‘‘){
                try{
                    result = new JSONFormat(data, 4).toString();
                } catch (e){
                    result = ‘<span style="color: #f1592a;font-weight:bold;">‘ + e + ‘</span>‘;
                }
            }
//            result = data;
            $("#main_data").html(result);
        }

        //关闭
        function closeClick(){
            $("#main_data").html(‘‘);
            parent.communicationEventHandlingWindow.hide();
        }

        //复制
        function selectAll(){
            $("#choose_all").zclip({
                path: "<%=baseUrl%>/global/js/ZeroClipboard.swf",
                copy: function(){
                    return $("#main_data").text();
                },
                beforeCopy:function(){/* 按住鼠标时的操作 */
                    $("#main_data").css("color","orange");
                },
                afterCopy:function(){/* 复制成功后的操作 */
                    var $copysuc = $("<div class=‘copy-tips‘><div class=‘copy-tips-wrap‘>? 复制成功</div></div>");
                    $("body").find(".copy-tips").remove().end().append($copysuc);
                    $(".copy-tips").fadeOut(3000);
                }
            });
        }

        //全选
        function SelectAllClicked(){
            //或者op1=$("#main_data")[0];
            var oP1 =  document.getElementById("main_data");
            var v =  document.createRange();
            v.selectNode(oP1);
            window.getSelection().addRange(v);

        }
    </script>
</head>
<body style="overflow: scroll">
<div>
    <input type="button" value="全选" onclick="SelectAllClicked()">
    <input type="button" value="复制" onclick="selectAll()" id="choose_all">
    <input type="button" value="关闭" onclick="closeClick()">
</div>
<hr/>
<div id="main_data" style="font-weight:normal"></div>
</body>
</html>


js 复制、全选功能

标签:

原文地址:http://my.oschina.net/u/2264370/blog/522527

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!