如何使用execommand获取选中区域字体大小!!!!! winformhtml编辑器 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 本帖最后由 showbo 于 2014-11-10 14:44:20 编辑 是因为说的不清楚是js 中的document.execommand 方法;execommand FontSize 设置或获取当前选中区的字体大小。 我怎么只能设置,不能获取呢? 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> 在给一个现成的mootools表单验证框架加功能,弄不出来了,只好来csdn求助~ 高分求个自适应布局 元素.document OR ownerDocument 是高手就进来,用fileupload上传时的问题,急啊……在线等 JS的修改 请帮忙 隐藏工具栏和地址栏的javascript的特效怎么写? 帮帮忙,看看这个选择问题出在哪了? 利用js排序 请问:把文字的字间距调宽一点的样式怎么定义啊,谢谢! 下拉菜单与数据库查询的问题 js加载如何做到容错? 是否停止运行此脚本?
是js 中的document.execommand 方法;
execommand FontSize 设置或获取当前选中区的字体大小。 我怎么只能设置,不能获取呢?
<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>