createTextRange Method--------------------------------------------------------------------------------Creates a TextRange object for the element.SyntaxoTextRange = object.createTextRange() Return ValueReturns a TextRange object if successful, or null otherwise. ResUse a text range to examine and modify the text within an object.ExamplesThis example uses the createTextRange method to create a text range for the document, and then uses the text range to display all the text and HTML tags in the document.<SCRIPT LANGUAGE="JScript"> var rng = document.body.createTextRange( ); if (rng!=null) { alert(rng.htmlText); } </SCRIPT> This example uses the createTextRange method to create a text range for the first button element in the document, and then uses the text range to change the text in the button.<SCRIPT LANGUAGE="JScript"> var coll = document.all.tags("BUTTON"); if (coll!=null && coll.length>0) { var rng = coll[0].createTextRange(); rng.text = "Clicked"; } </SCRIPT> Standards InformationThere is no public standard that applies to this method.
<script> function rdl_doTextRange(){ var oMessage=document.all("oMessage"); var oTextRange=document.body.createTextRange(); if (oTextRange!=null) alert(oTextRange.htmlText); } </script> <span id=oMessage>我是一些文字。</span> <br><br> <input type=button value=" 建立选择区" onclick="rdl_doTextRange();">
Return ValueReturns a TextRange object if successful, or null otherwise. ResUse a text range to examine and modify the text within an object.ExamplesThis example uses the createTextRange method to create a text range for the document, and then uses the text range to display all the text and HTML tags in the document.<SCRIPT LANGUAGE="JScript">
var rng = document.body.createTextRange( );
if (rng!=null) {
alert(rng.htmlText);
}
</SCRIPT>
This example uses the createTextRange method to create a text range for the first button element in the document, and then uses the text range to change the text in the button.<SCRIPT LANGUAGE="JScript">
var coll = document.all.tags("BUTTON");
if (coll!=null && coll.length>0) {
var rng = coll[0].createTextRange();
rng.text = "Clicked";
}
</SCRIPT>
Standards InformationThere is no public standard that applies to this method.
语法:
oTextRange = object . createTextRange ()
参数:
无
返回值:
oTextRange : 对象(Element)。如果成功的话返回被建立的 TextRange 对象。 说明:
为 object 建立 TextRange 对象。
使用此 TextRange 对象可以检索和修改 object 内的文本。 TextRange 对象的 htmlText 特性尤其提供了方便。
应用于:
IE4.0+ BODYBUTTONINPUT type=buttonINPUT type=hiddenINPUT type=passwordINPUT type=resetINPUT type=submitINPUT type=textTEXTAREA
function rdl_doTextRange(){
var oMessage=document.all("oMessage");
var oTextRange=document.body.createTextRange();
if (oTextRange!=null) alert(oTextRange.htmlText);
}
</script>
<span id=oMessage>我是一些文字。</span>
<br><br>
<input type=button value=" 建立选择区" onclick="rdl_doTextRange();">