一个分享个人学习、开发经验的Blog,http://www.joyphper.net

一个很简单很实用的Javascript 在线排版工具

posted @ 2010-10-04 15:46 | 阅读:6282 | 评论:0 | 分类: Javascript

 

<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
<title>编辑排版工具</title> 
</head> 
<style type="text/css">   
<!--  
body {font-size:10pt; margin:0px; padding:0px;}  
td {font-size:10pt}  
textarea{width:100%; height:99%; border:1px solid #666; overflow:auto;}  
--> 
</style> 
<script src="common/fck_dialog_common.js" type="text/javascript"></script> 
<script language="javascript" type="text/javascript">   
function format()  
{  
        var formBody = "
"+document.getElementById("thebody").value;  
        if(document.getElementById("thebody").value==''){   
            alert('请输入排版内容!');  
            document.getElementById("thebody").focus();   
            return false;  
        }else{  
            formBodyformBody = formBody.replace(/ | /ig,"");  
            formBodyformBody = formBody.replace(/
/ig,"
");  
            formBodyformBody = formBody.replace(/

/ig,"
");  
            formBodyformBody = formBody.replace(/

/ig,"
");  
            formBodyformBody = formBody.replace(/

/ig,"
");  
            formBodyformBody = formBody.replace(/

/ig,"
");  
            formBodyformBody = formBody.replace(/
/ig,"  
");  
            formBodyformBody = formBody.replace("

","
");  
            //formBody="
"+formBody;  
            formBodyformBody = formBody.replace(/ | /ig,"");  
            formBodyformBody = formBody.replace(/
/ig,"

  ");  
            formBodyformBody = formBody.replace("

","");  
            document.getElementById("thebody").value=formBody;  
        }  
}  
function copy(ob)  
{  
    var obj=findObj(ob);  
    if (obj) {   
        obj.select();  
        js=obj.createTextRange();  
        js.execCommand("Copy");  
    }  
}  
 
function paste(ob)   
{  
    var obj=findObj(ob);   
    if (obj)  
    {   
        obj.select();  
        js=obj.createTextRange();  
        js.execCommand("Paste");  
    }  
}  
function findObj(n, d) {   
    var p,i,x; if(!d) d=document;   
    if((p=n.indexOf("?"))>0&&parent.frames.length)   
    {  
        d=parent.frames[n.substring(p+1)].document;  
        nn=n.substring(0,p);  
    }  
    if(!(x=d[n])&&d.all) x=d.all[n];   
    for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];  
    for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);  
    if(!x && document.getElementById) x=document.getElementById(n);  
    return x;  
}  
function chklen()  
{  
    var strlen;  
    strlen= KKsForm.Content.value.length;  
    alert("目前长度" + strlen + "文字
");  
    return;  
}  
</script> 
</head> 
<body bgcolor="#cecece"> 
<div> 
  <center> 
    <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="700" bgcolor="#FFFFFF" height="440"  > 
    <form method="POST" action="#"  name='KKsForm' id="KKsForm" > 
        <tr > 
            <td height="30" bgcolor="#FAFAFA" align="center">   
                <input type="button" value="粘贴文章" onClick="paste('content')"> 
                <input type="button" value="自动排版" title="系统自动排版" onClick="javascript:format()" >    
                <input type="button" value="统计字数" title="统计输入汉字数" onClick="chklen()"> 
                <input type="button" value="复制文章" onClick="copy('content')">   
                <input type='reset' value='清空内容' name='cmdReset'> 
            </td> 
        </tr> 
        <tr> 
            <td height="300" bgcolor="#FAFAFA">   
                <textarea id='thebody' name="Content"></textarea> 
            </td> 
        </tr> 
      </form> 
      <tr> 
            <td align="center" height="20px;">CopyRight©2010 E-mail:stjdydayou@163.com QQ:97142822</td> 
      </tr> 
    </table> 
  </center> 
</div> 
</body> 
</html> 

 

TAG: php学习 , 排版工具 , 在线排版

共有0条评论 发表评论>>

点击换一张验证码