回 帖 发 新 帖 刷新版面

主题:[原创]在线编辑器问题

大家好,下面是一个添加新闻的代码,后台发布信息时控制格式(以加粗为例)只能用<b></b>来操作,现在想把它改成,选中文本,点击加粗的图片,就可以把文本加粗.
谢谢大家了,帮我改一下,只要能够加粗就行了,其它的功能类似我自己再改好了,谢谢大家了...
代码:
<%if Session("Ulogin")<>"yes" then
    Response.Redirect ("login.asp")
end if%>    

<html>

<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 6.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<LINK href="../css/main.css" rel=stylesheet type="text/css">
<title>发布新督导室信息</title>
<script language="JavaScript">
<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
    window.open(theURL,winName,features);
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=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=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') {
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (val<min || max<val) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '—  您必须输信息标题!\n'; }
  } if (errors) alert('在提交数据时发生如下错误:\n'+errors);
  document.MM_returnValue = (errors == '');
}
//-->
</script>
<style type="text/css">
<!--
.style3 {
    font-size: 18px;
    font-weight: bold;
    color: #000000;
}
.style4 {
    color: #FF0000;
    font-size: 18px;
}
.style5 {color: #FF0000}
.style6 {color: #000000}
.style7 {color: #000000; font-size: 18px; }
-->
</style></head>

<body>
<!--#include file="head2.asp"-->
<div align="center">
  <p><span class="style3">发布信息</span><br>
  </p>
</div>
<form method="POST" name="myfrom" action="news_to_server.asp">
 
  <table width="770" height="463" border="1" align="center" cellpadding="3" cellspacing="0" bordercolor="#000000" >
    <tr>
      <td width="13%" height="42" align="center">&nbsp;<span class="style4"><span class="style6">标  题</span>&nbsp;</span></td> 
      <td width="87%" height="42"><input type="text" name="title" size="20" class="smallInput" >
      <span class="style5">*20个字以内描述(注:如果是发布信息周报,请在此写期数即可,如:“第二十期”)</span></td>
    </tr>
    <tr>
      <td height="38" align="center" class="style7">来  自</td>
      <td height="38"><input name="from" type="text" size="20">
        <span class="style5">*请填写你所属的部门</span></td>
    </tr>
    <tr>
      <td height="34" align="center" class="style7">类  别</td>
      <td height="34"><select name="group">
        <option value="ddszt">督导室专题</option>
        <option value="xsxxzb">学生信息周报</option>
        <option value="xzfc">学子风采</option>
        <option value="xxyd">学习园地</option>
        <option value="hyb">回音壁</option>
        <option value="ggl">公告栏</option>
        <option value="zxdt">最新动态</option>
      </select></td>
    </tr>
    <tr>
      <td height="71" align="center" background="../images/point3.gif"><span class="style7">内  容</span></td>
      <td width="87%"  valign="middle"><textarea rows="25" name="content" cols="90" style="font-size: 10pt"></textarea></td>
    </tr>
  </table>
  <div align="center"></div>
  <p align="center">
    &nbsp;<input type="submit" value="发送" name="B1" > 
    <input name="重置" type="reset" value="重置" >
  </p>
</form>

<!--#include file="../tail.asp"--> 
</body>

</html>

回复列表 (共3个回复)

沙发

function bold()
{
  var range = document.selection.createRange();
  range.text = "<b>" + range.text + "</b>";
}

板凳

写编辑器那有用这个加粗的 这样写还不如用Ubb代码呢: range.text = "<b>" + range.text + "</b>";
有个专门的命令是document.execcommand(加粗改变颜色插入超连接很多功能) 就去看下这个命令你会发现编辑器其实很简单的。
呵呵

3 楼

给你地址上面一个简单的编辑器代码:
http://hi.baidu.com/yanjinbin/blog/item/68b202f450539eef7709d76b.html
你可以参考下。呵呵。

我来回复

您尚未登录,请登录后再回复。点此登录或注册