我想知道文本框的常规 setSelectionRange 是否在新的 Firefox 夏季中不起作用。在 MDN 站点(Mozilla 开发者中心)中,它被指定为:
setSelectionRange( start, end ) 返回类型:无返回值 设置文本框的选定部分,其中 start 参数是要选择的第一个字符的索引,end 参数是选择后字符的索引。将两个参数设置为相同的值以将光标移动到相应的位置而不选择文本。
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<window id="yourwindow"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:h="http://www.w3.org/1999/xhtml">
<button label="x" oncommand="sel()" />
<textbox id="id" multiline="true"
value="This is some text that could wrap onto multiple lines."/>
<script type="text/javascript">
<![CDATA[
function sel(){
var textbox = document.getElementById("id");
textbox.setSelectionRange( 1 , 2 );
}
]]>
</script>
</window>