IE11非兼容模式下的range.moveStart()函数

时间:2015-12-07 08:38:45

标签: javascript internet-explorer internet-explorer-11

我有一个文本框(数字),可以输入或删除数字。 按下退格键时,将删除某个位置的值,并调用如下的javascript函数。

function getCaretPosition(textObject)
{
	var position = 0;
	if(textObject.createTextRange)
	{
		
		var range="";
		if (window.getSelection)
		{
			range = window.getSelection();
		}
		if (document.getSelection)
		{
		range = document.getSelection();
		}
		if(range=="")
		{
			if (document.selection)
			{
			range = document.selection.createRange().duplicate();
			}
		}
		
		//range = document.selection.createRange().duplicate();
		range.moveStart('textedit', -1);
		position = range.text.length;
	}
	else if(textObject.setSelectionRange)
		position = textObject.selectionEnd;
	return position;
}

当我在IE11非兼容模式下运行应用程序并使用文本字段上的退格键时,会出现如下错误:

“对象不支持属性或方法'moveStart'”

我猜测IE11中不支持moveStart方法。 有人可以建议如何克服这个问题吗? 这似乎在IE11兼容模式下工作正常。

0 个答案:

没有答案
相关问题