• ComponentOne Wijmo HTML Editor 在光标处添加文本


    ComponentOne Wijmo Editor 是一款强大的HTML 编辑器,可以插入table, image, links 等标签,但是没有在光标处直接插入标签的功能。但是,现在Wijmo Editor 是一款基于 jQuery 控件。现在们可以通过客户端 object 模型去实现。
    在本文中,我们将通过自定义方法来实现该功能。
    首先,我们要插入wijmo:C1Editor 标签来展示 Wijmo Editor 。在使用 iFrame 加载Wijmo Editor 之后,我们就可以使用 createRange 和 execCommand 方法来实现在光标处插入文本了。
    下面是实现该功能的完整代码: 

    <script type="text/javascript"> 
    function insetTextAtCursor(inputText) { 
        //get the container 
        var $designView = $("iframe", $(".wijmo-wijeditor-container")), 
             win, doc, range; 
      
        if ($designView && $designView.length > 0) { 
           //retrieve the Window object generated by the iframe 
            win = $designView[0].contentWindow; 
         } 
        if (win) { 
             //access the document object 
             doc = win.document; 
         } 
         if (doc) { 
            try { 
               //check if the browser is IE 
               if ($.browser.msie) { 
                  //insert the given text 
                  doc.body.focus(); 
                  range = doc.selection.createRange(); 
                  range.pasteHTML(inputText); 
                  range.collapse(false); 
                  range.select(); 
               }
    else { doc.execCommand('insertText', false, inputText); } } catch (e) { } } } </script>

    截图展示:

    ComponentOne Wijmo Editor

    你也试一试?

    Demo下载

    很高兴能和大家分享 ComponentOne 的使用方法、讨论 ComponentOne 使用过程中遇到的问题。

    葡萄城控件产品网站:http://www.gcpowertools.com.cn/ 
    葡萄城技术支持论坛:http://gcdn.grapecity.com/

  • 相关阅读:
    caioj 1914 & CH 0x20搜索(0x27A*)例题1:第K短路 Remmarguts'Date
    多项式的化简求法
    caioj 1715 表达式的转换
    HDU 2829 Lawrence
    山海经 (线段树)
    神奇的KMP
    浅谈zkw线段树(by Shine_hale)
    线段树补充
    浅谈线段树(by Shine_hale)
    k短路
  • 原文地址:https://www.cnblogs.com/C1SupportTeam/p/2608045.html
Copyright © 2020-2023  润新知