解决方案 »

  1.   

    本帖最后由 showbo 于 2014-11-10 14:44:20 编辑
      

  2.   

    是因为说的不清楚
    是js 中的document.execommand 方法;
    execommand FontSize 设置或获取当前选中区的字体大小。 我怎么只能设置,不能获取呢? 
      

  3.   

    execommand只是执行命令,获取样式要用select和range对象
    <iframe name="richEdit" id="richEdit-id" src="about:blank"></iframe><br />
    <input type="button" onclick='getFontSize()' value="获取选中内容的font-size" />
    <script>
        function getFontSize() {
            var doc = frames["richEdit"].document        var rng = doc.selection.createRange();
            alert(rng.parentElement().style.fontSize)    }
        window.onload = function () {
            frames["richEdit"].document.designMode = "on";
            //IE下不用计时器延时执行代码,获取到的frames['richEdit'].document会为空导致出错
            setTimeout(function () {
                var editor = frames['richEdit'].document.body;
                editor.innerHTML += '<span style="font-size:20px">20px的字符</span>abcdefg';
            }, 10);
        }
    </script>