找回密码
 立即注册

QQ登录

只需一步,快速开始

iceman

社区贡献组

270

主题

1万

帖子

1万

积分

社区贡献组

积分
19311

活字格认证微信认证勋章元老葡萄

iceman
社区贡献组   /  发表于:2012-7-25 12:04  /   查看:4886  /  回复:0
ComponentOne Wijmo Editor 是一款强大的HTML 编辑器,可以插入table, image, links 等标签,但是没有在光标处直接插入标签的功能。但是,现在Wijmo Editor 是一款基于 jQuery 控件。现在们可以通过客户端 object 模型去实现。
在本文中,我们将通过自定义方法来实现该功能。
首先,我们要插入wijmo:C1Editor 标签来展示 Wijmo Editor 。在使用 iFrame 加载Wijmo Editor 之后,我们就可以使用 createRange 和 execCommand 方法来实现在光标处插入文本了。
下面是实现该功能的完整代码:
  1. <script type="text/javascript">
  2.   
  3. function insetTextAtCursor(inputText) {
  4.     //get the container
  5.     var $designView = $("iframe", $(".wijmo-wijeditor-container")),
  6.          win, doc, range;
  7.   
  8.     if ($designView &amp;&amp; $designView.length > 0) {
  9.         //retrieve the Window object generated by the iframe
  10.         win = $designView[0].contentWindow;
  11.      }

  12.     if (win) {
  13.          //access the document object
  14.          doc = win.document;
  15.      }
  16.   
  17.      if (doc) {
  18.         try {
  19.            //check if the browser is IE
  20.            if ($.browser.msie) {
  21.               //insert the given text
  22.               doc.body.focus();
  23.               range = doc.selection.createRange();
  24.               range.pasteHTML(inputText);
  25.               range.collapse(false);
  26.               range.select();
  27.            } else {
  28.               doc.execCommand('insertText', false, inputText);
  29.            }
  30.         } catch (e) {
  31.      }
  32.    }
  33. }
  34. </script>
复制代码

截图展示:

Demo下载:

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x

0 个回复

您需要登录后才可以回帖 登录 | 立即注册
返回顶部