以下是测试代码,为什么点击textarea的时候正常,而text却提示“参数无效”呢?求大家帮看看,能不能改成对两者都有效的函数
<HTML> <HEAD> <TITLE> 定位 </TITLE>
<META content= "text/html; charset=gb2312 " http-equiv=Content-Type>
<SCRIPT language=JScript>
<!--
function savePos(textBox){
if(document.selection){
var range = document.selection.createRange();
if(range.parentElement().id == textBox.id){
var range_all = document.body.createTextRange();
range_all.moveToElementText(textBox);
for (start=0; range_all.compareEndPoints( "StartToStart ", range) < 0; start++)
range_all.moveStart( 'character ', 1);
for (var i = 0; i <= start; i ++){
if (textBox.value.charAt(i) == '\n ')
start++;
}
var range_all = document.body.createTextRange();
range_all.moveToElementText(textBox);
for (end = 0; range_all.compareEndPoints( 'StartToEnd ', range) < 0; end ++)
range_all.moveStart( 'character ', 1);
for (var i = 0; i <= end; i ++){
if (textBox.value.charAt(i) == '\n ')
end ++;
}
}
}
}
//-->
</script>