var textbox = document.forms[0].elements["firstText"];EventUtil.addHandler(textbox,"select",function (event) {alert(textbox.value.substring(textbox.selectionStart,textbox.selectionEnd));});如果要兼容更老版本的话,可以使用下面的代码:var textbox = document.forms[0].elements["firstText"];EventU...
thestartand theend(exclusive) character position, respectively. In case the end value is smaller than the start, substring is smart enough toswapthe values before doing the string extraction. An example of substring
substring() Parameters Thesubstring()method takes in: indexStart- The index of the first character to start including in the returned substring. indexEnd(optional) - The index before which to stop extraction. (Exclusive) If omitted, it extracts till the end of the string. Notes: Anyargument ...
JavaScript是一种解释执行的脚本语言,是一种动态类型、弱类型、基于原型的语言,内置支持类型,它遵循ECMAScript标准。它的解释器被称为JavaScript引擎,为浏览器的一部分,广泛用于客户端的脚本语言,主要用来给HTML增加动态功能。 几乎所有主流的语言都可以编译为JavaScript,进而能够在所有平台上的浏览器中执行,这也体现了Java...
(pos=='b')returnstr.substring(str.indexOf(char)+1);// If the position indicator is 'a' (after), return the substring before the specified character.elseif(pos=='a')returnstr.substring(0,str.indexOf(char));// If the position indicator is neither 'a' nor 'b', return the original...
alert(this.value.substring(this.selectionStart, this.selectionEnd)); }); 除了IE,其他浏览器均支持这两个属性(IE9+已支持)。IE不支持,而提供了另一个方案:selection对象,属于document。这个对象保存着用户在整个文档范围内选择的文本信息。 //浏览器兼容 ...
return text.value.substring(text.selectionStart, text.selectionEnd); } else if (document.selection) {//IE return document.selection.createRange().text;//获取IE选择的文本 } } PS:有一个最大的问题,就是IE在触发select事件的时候,在选择一个字符后立即触发,而其他浏览器是选择想要的字符释放鼠标键后才...
获取选中文本:textbox.value.substring(textbox.selectionStart, textbox.selectionEnd);浏览器支持:IE9+、Firefox、Safari、Chrome 和 Opera。 IE8 及之前版本方案:document.selection 对象,其中保存着用户在整个文档范围内选择的文本信息。(无法确定用户选择的是页面中哪个部位的文本) ...
return textbox.value.substring(textbox.selectionStart, textbox.selectionEnd); } else if (document.selection) { return document.selection.createRange().text; } } var textbox = document.forms[0].elements["textbox1"]; EventUtil.addHandler(textbox, "select", function (event) { ...
substr() Returns a part of a string by taking the starting position and length of the substring. substring() Returns a part of the string from the specified start index (inclusive) to the end index (exclusive). slice() Returns a part of the string from the specified start index (inclusiv...