为什么此代码在IE中不起作用!

问题描述:

<HTML>
<HEAD><TITLE>Selection</TITLE>
<SCRIPT type="text/javascript">
function disp()
{
  var text = document.getElementById("text");
  var t = text.value.substr(text.selectionStart,text.selectionEnd-text.selectionStart);
  alert(t+"\nSelectionStart:"+text.selectionStart);

}
</SCRIPT>
</HEAD>
<BODY>

<TEXTAREA id="text">Hello, How are You?</TEXTAREA><BR>
<INPUT type="button"  value="Select text and click here"  onclick="disp();"/>
</BODY>
</HTML>


text.value.substr(text.selectionStart,text.selectionEnd-text.selectionStart);


检查第二个参数substr.它应该是整数.
试试这个:


Check your second parameter of substr. It should be integer.
Try this:

text.value.substr(text.selectionStart,10);





--Amit





--Amit


亲爱的朋友,

Dear Friend,

function disp()
{
    var text = document.getElementById("text").value;
    //  var t = text.substr(text.selectionStart,text.selectionEnd-text.selectionStart)
    var t = text.substr(text.selectionStart,10);
    alert(t+"\nSelectionStart:"+text.selectionStart);
}



< INPUT type ="button" id ="text" name ="text" value =选择文本并单击此处" onclick ="disp()"/>

希望这能满足您的要求.



<INPUT type="button" id="text" name="text" value="Select text and click here" onclick="disp()"/>

Hope this will fulfill your requirement.