TextRange对象的属性和方法定义如下:
htmlText属性: 对应于TextRange对象区域内的文本和HTML代码.该属性可读可写,可以通过对该属性赋新值来改变TextRange区域内的HTML代码内容.
Text属性: 对应于TextRange对象区域内的文本内容(忽略其中的HTML代码).该属性同样是可读可写的,可以通过Text属性赋新值的方法来改变TextRange区域内的文本内容.同htmlText属性不同的是,text属性不包含区域内的HTML代码. 例如: 对于代码
<body> This is the <strong> TextRange </strong> example;
</body>
<script>
var myTextRange = document.body.createTextRange();
</script>
所创建的TextRange对象,其中htmlText属性值为: This is the <strong> TextRange </strong> example; 而text属性值为: This is the TextRange example;