【笔记】 《js权威指南》- 第15章 脚本化文档 - 15.10 其他文档特性

1.Doucument属性:



2.获取选中的文本:

function getSelectedText() {
    if(window.getSelection)
        return window.getSelection().toString();
    else if ( document.selection.createRange().text;
}

//兼容ie外的浏览器获取输入文本域中的选中内容
elt.value.substring(elt.selectionStart, elt.selectionEnd);

3.可编辑的内容:

(1).通过编辑标签contenteditable属性或者编辑JS元素的contenteditable属性是元素变得可编辑;

<div id="editor" contenteditable>
CLick to edit
</div>

(2). 通过设置document对象的designMode属性为“on”;

(3). 使用文本编辑命令来编辑文本:

//参数1:指令
//参数2:建议使用false, true为浏览器提示用户输入值
//参数3:超链接url
document.execCommand("bold", false, url);

//检测浏览器是否兼容指令:
document.queryCommandSupport("bold");

//检测当前是否能使用某指令:
document.queryCommandEnabled("bold");

//获取某指令当前使用状态
document.queryCommandState("bold");

//获取某些指令相关联的值:
document.queryCommandValue("fontname");

//当前选取出现几种不同的状态:
document.queryCommandIndeterm("bold");

可能兼容的指令列表:



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值