html编辑器 学习

原文链接: http://www.cnblogs.com/flex_fly/archive/2011/01/19/1938998.html

项目中有一个小功能 要实现  text字符框中显示斜体的效果  所以参考了xheditor, 网上搜索等 

<script src="jquery/jquery-1.4.2.min.js"></script>
<script>
  $(document).ready(function(){
//     var win = $('#ifr').contentWindow;
    var win =  document.getElementById('ifr').contentWindow.document;
      
    var html = "<html><body></body></html>"
    var s = $('#text_i').val();

   //针对IE and !IE 的情况
    win.designMode = "on";
    win.contentEditable = true;

   //

    win.open();
    //win.write(html);
    win.write(s);
    win.close();
     //alert(win);
  });
</script>
<span>

   <input type="text" id="text_i" value="<i>斜体</i>" style="display:none;"/>

   <iframe id="ifr" width="60" height="20" src="javascript:;">
      
   </iframe>
</span>

转载于:https://www.cnblogs.com/flex_fly/archive/2011/01/19/1938998.html

猜你喜欢

转载自blog.csdn.net/weixin_30335575/article/details/94787521