让网页复制剪贴板中的内容到文本框(http://hi.baidu.com/tracyjay/blog/item/de2490295285ff26d52af1ac.html)

<html xmlns="http://www.w3.org/1999/xhtml ">
<head>
<title>让网页复制剪贴板中的内容到文本框</title>
<style type="text/css">
H1 {
PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 18px; PADDING-BOTTOM: 4px; MARGIN: 0px; PADDING-TOP: 40px; TEXT-

ALIGN: center
}
.convertbutton {
FONT-WEIGHT: bold; FONT-SIZE: 24px
}
#t {
PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 12px; PADDING-BOTTOM: 0px; MARGIN: 0px; WIDTH: 370px; LINE-HEIGHT:

12px; PADDING-TOP: 0px
}
#s {
PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 12px; PADDING-BOTTOM: 0px; MARGIN: 0px; WIDTH: 370px; LINE-HEIGHT:

12px; PADDING-TOP: 0px
}
#content {
WIDTH: 760px
}
BODY {
FONT-SIZE: 9pt; FONT-FAMILY: "宋体"
}
P {
FONT-SIZE: 9pt; FONT-FAMILY: "宋体"
}
BR {
FONT-SIZE: 9pt; FONT-FAMILY: "宋体"
}
A:link {
FONT-SIZE: 9pt; COLOR: #000099; TEXT-DECORATION: none
}
A:visited {
FONT-SIZE: 9pt; COLOR: #0000ff; TEXT-DECORATION: none
}
A:active {
FONT-SIZE: 9pt; COLOR: #ff9a00; TEXT-DECORATION: underline
}
A:hover {
FONT-SIZE: 9pt; COLOR: #ff0000; TEXT-DECORATION: underline
}
TD {
FONT-SIZE: 9pt; FONT-FAMILY: "宋体"
}
</style>
<script language="javascript" type="text/javascript">
var tblChars = [['┏','┓','┗','┛','┯','┷','┃','│', '━'],
                ['╔','╗','╚','╝','╤','╧','║','│', '═'],
                ['┌','┐','└','┘','┬','┴','│','┆', '—'],
                [' ',' ',' ',' ',' ',' ',' ',' ', ' '],
                ['','','','','','','│','│', ''],];

var tblTemplet = 1;
var blankChar = ' ';
var width=20;
var height=8;
function convert(){
    var s = document.getElementById("s").value.toString();
    s = s.replace(//r/g, "");
    if(s.length == 0){
        document.getElementById("s").focus();
        alert("请首先输入要转换格式的文字。");
        return;
    }

    var ary = [];
    var i,j, index;
    var t = "";
    index = 0;
    width = document.getElementById("x").value * 1;
    height = document.getElementById("y").value * 1;
    tblTemplet = document.getElementById("tbl").value * 1;
   
    for(i=width*2; i>=0; i--){
        ary[i] = new Array();
    }
    while(index < s.length){
        for(i=width*2; i>=0; i--){
            for(j=0; j<=(height+1); j++){
                if( i == (width * 2)){
                    if(j==0){
                        ary[i][j] = tblChars[tblTemplet][1];
                    }else if(j == (height + 1)){
                        ary[i][j] = tblChars[tblTemplet][3];
                    }else{
                        ary[i][j] = tblChars[tblTemplet][6];
                    }
                }else if( i== 0){
                    if(j==0){
                        ary[i][j] = tblChars[tblTemplet][0];
                    }else if(j == (height + 1)){
                        ary[i][j] = tblChars[tblTemplet][2];
                    }else{
                        ary[i][j] = tblChars[tblTemplet][6];
                    }
                }else if( i % 2 == 0){
                    if(j==0){
                        ary[i][j] = tblChars[tblTemplet][4];
                    }else if(j == (height + 1)){
                        ary[i][j] = tblChars[tblTemplet][5];
                    }else{
                        ary[i][j] = tblChars[tblTemplet][7];
                    }
                }else if(j == 0 || j == (height + 1)){
                    ary[i][j] = tblChars[tblTemplet][8];
                }else{
                    var c = getChar(s, index++);
                    if (c == '/n' || c == '/r'){
                        /*if(j == 1){
                            j = 0;
                            continue;
                        }else{*/
                            while(j<(height+1)){
                                ary[i][j] = blankChar;
                                j++;
                            }
                            j = height;
                        //}
                    }else{
                        ary[i][j] = c;
                    }
                }
            }
        }
        for(j=0; j<=(height + 1); j++){
            for(i=0; i<=width*2; i++){
                t += ary[i][j];
            }
            t += "/r/n";
        }
        t += "/r/n";

    }

    document.getElementById("t").value = t;

    setCookie("x", width + '');
    setCookie("y", height + '');
   
}

var half =

['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u',

'v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
'(',')','[',']','{','}','<','>','*','&','^','%','$','#','@','!','~','`','+','-','=','_','|','//','/'','"',';',':','.',',','?',

'/',' ','(',')','【','】','《','》', '…', '—', '~', '“', '”', '‘', '’','「','」','『','』','【','】','《','》','〈','〉',
'(',')','{','}'];
var full = ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','g','h','i','j','k','l','m',
'n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M',
'N','O','P','Q','R','S','T','U','V','W','X','Y','Z','(',')','【','】','{','}','《','》','*','&',
'^','%','$','#','@','!','~','‘','+','-','=','_','|','\','’','”',';',':','。',',','?',
'/', blankChar,'(',')','【','】','《','》', '┇', '│', '§','「','」','『','』','「','」','『','』',
'【','】','《','》','^','〉','(',')','{','}'];


function getChar(s, index){
    if(index >= s.length){
        return blankChar;
    }
    var c = s.charAt(index);
    for(var i=0; i<half.length; i++){
        if(c == half[i]){
            c = full[i];
        }
    }
    return c;
}


function copyresult(){
    var s = document.getElementById("t").value.toString();
    if (s.length == 0){
        alert("现在没有转换格式后的文字,请首先转换文字。");
        return;
    }
    var e=document.getElementById("t");
    e.focus();
    e.select();
    if(document.all){
        var r = e.createTextRange();
        r.execCommand("Copy");
    }else{
        alert("您的浏览器不支持javascript剪贴板操作,请用Ctrl + C拷贝结果文字");
        return;
    }
}

function setCookie(name, value, expires, path, domain, secure) {
    var ck = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
    document.cookie = ck;
}

function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

function init(){
    document.getElementById('s').focus();
    var v;
    v = getCookie("templet");
    if( v != null){
        document.getElementById("tbl").value = v;
    }
    v = getCookie("x");
    if( v != null){
        document.getElementById("x").value = v;
    }
    v = getCookie("y");
    if( v != null){
        document.getElementById("y").value = v;
    }
}
function get(){
  
    var wby = document.getElementById("s");
    var isValue=clipboardData.getData("text");
    wby.value=isValue
}
</script>
</head>
<BODY>
<CENTER>
<DIV id=content>

<P align=left><FONT color=#0066ff>1、把您要转换的文字输入到下面的输入框中:</FONT>
<BR>
<input type="button" οnclick="get()" value="或从剪贴板读入"></BR><BR><TEXTAREA id=s rows=3 cols=30></TEXTAREA></P>
<P align=left>每页 <SELECT id=x>
<OPTION value=5>5</OPTION> <OPTION value=8>8</OPTION> <OPTION
value=9>9</OPTION> <OPTION value=10>10</OPTION> <OPTION value=11 selected>11</OPTION>
<OPTION value=12>12</OPTION> <OPTION value=13>13</OPTION> <OPTION
value=14>14</OPTION> <OPTION value=15>15</OPTION> <OPTION value=16>16</OPTION>
<OPTION value=17>17</OPTION> <OPTION value=18>18</OPTION> <OPTION
value=19>19</OPTION> <OPTION value=20>20</OPTION> <OPTION value=25>25</OPTION>
<OPTION value=30>30</OPTION></SELECT> 竖行,每竖行 <SELECT id=y> <OPTION
value=5>5</OPTION> <OPTION value=8>8</OPTION> <OPTION value=9>9</OPTION>
<OPTION value=10 selected>10</OPTION> <OPTION value=11>11</OPTION> <OPTION
value=12>12</OPTION> <OPTION value=13>13</OPTION> <OPTION value=14>14</OPTION>
<OPTION value=15>15</OPTION> <OPTION value=16>16</OPTION> <OPTION
value=17>17</OPTION> <OPTION value=18>18</OPTION> <OPTION value=19>19</OPTION>
<OPTION value=20>20</OPTION> <OPTION value=25>25</OPTION> <OPTION
value=30>30</OPTION></SELECT> 个字使用 <SELECT id=tbl> <OPTION
value=0>粗实线+细实线</OPTION> <OPTION value=1 selected>双实线+细实线</OPTION> <OPTION
value=2>细实线+细虚线</OPTION> <OPTION value=3>无线框</OPTION> <OPTION
value=4>无头尾线框</OPTION></SELECT><br><INPUT οnclick="javascript:convert();" type="button" value="转换↓"/>
<a href="javascript:copyresult();">拷贝转换结果</A>
<p align="left"><FONT color=#0066ff>3、结果就在下面,你可以拷贝到论坛、博客里面去了。</font><br><TEXTAREA id="t"
οnmοuseοver=this.focus();this.select(); rows=5 readOnly="readOnly" cols=30></TEXTAREA></p>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值