当前位置: 首页 > 图文教程 > 网络编程 > Javascript > 修改发贴的编辑功能

Javascript
jquery 交替为表格添加样式的代码
jquery下操作HTML控件的实现代码
JQuery获取元素文档大小、偏移和位置和滚动条位置的方法集合
海量经典的jQuery插件集合
JavaScript获取鼠标坐标的函数(兼容IE、FireFox、Chrome)
JavaScript关于select的相关操作说明
jQuery的一些特性和用法整理小结
用jQuery扩展自写的 UI导航
JQuery 引发两次$(document.ready)事件
javascript实现的基于金山词霸网络翻译的代码
Span元素的width属性无效果原因及解决方案
javascript 不间断的图片滚动并可点击
利用onresize使得div可以随着屏幕大小而自适应的代码
extjs 为某个事件设置拦截器
javascript 构建一个xmlhttp对象池合理创建和使用xmlhttp对象
javascript 特性检测并非浏览器检测
20个非常有用的PHP类库 加速php开发
前淘宝前端开发工程师阿当的PPT中有JS技术理念问题
AJAX的跨域与JSONP(为文章自动添加短址的功能)
JavaScript学习笔记(十)

Javascript 中的 修改发贴的编辑功能


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 51 ::
收藏到网摘: n/a

以下代码可以做到在光标处插入代码,如果有选择区域,则会使用选择区域生效。
1、vbcode.js 文件中
替换函数 vbcode 为下面内容
复制代码 代码如下:

function vbcode(theform,vbcode,prompttext) {
 if (theform.message.createTextRange && theform.message.caretPos) {
  var caretPos = theform.message.caretPos;
  if(caretPos.text.length > 0)
   caretPos.text = "["+vbcode+"]" + caretPos.text + "[/"+vbcode+"]";
  else
   caretPos.text = "["+vbcode+"]" + "[/"+vbcode+"]";
 }
 theform.message.focus();
}

替换函数 fontformat 为下面内容
复制代码 代码如下:

function fontformat(theform,thevalue,thetype) {
 if (theform.message.createTextRange && theform.message.caretPos) {
  var caretPos = theform.message.caretPos;
  if(caretPos.text.length > 0)
   caretPos.text = "["+thetype+"="+thevalue+"]" + caretPos.text + "[/"+thetype+"]";
  else
   caretPos.text = "["+thetype+"="+thevalue+"]" + "[/"+thetype+"]";
 }
 theform.sizeselect.selectedIndex = 0;
 theform.fontselect.selectedIndex = 0;
 theform.colorselect.selectedIndex = 0;
 theform.message.focus();
}

替换函数 smilie 为下面内容
复制代码 代码如下:

function smilie(thesmilie) {
// inserts smilie text
 if (document.vbform.message.createTextRange && document.vbform.message.caretPos) {
  var caretPos = document.vbform.message.caretPos;
  caretPos.text = thesmilie;
 }
 document.vbform.message.focus();
}

加入下面代码
复制代码 代码如下:

function storeCaret(textEl) {
 if (textEl.createTextRange)
  textEl.caretPos = document.selection.createRange().duplicate();
}

2、color.js 文件
查找函数 insertTag 替换成下面内容
复制代码 代码如下:

function insertTag(MyString)
{
 bbopen=''
 bbclose='';
 if (MM_findObj('message').createTextRange && MM_findObj('message').caretPos) {
  var text = bbopen + bbclose ;
  var caretPos = MM_findObj('message').caretPos;
  if(caretPos.text.length > 0)
   caretPos.text = bbopen + caretPos.text + bbclose;
  else
   caretPos.text = text;
 } else {
  MM_findObj('message').value += bbopen + bbclose;
 }
 MM_findObj('message').focus();
 return;
}

3、修改 editpost、newthread 和 newreply 模板
查找
$postinfo[message]
替换成
$postinfo[message]