我不知道例程setSelectionRange文本框在新的Firefox夏天不起作用。在MDN站點(Mozilla開發中心)將其指定:XUL文本框setSelectionRange
setSelectionRange(開始,結束) 返回類型:無 設置的文本框,其中,所述開始參數是的索引的選擇的部分的返回值要選擇的第一個字符和結束參數是選擇後字符的索引 。將兩個參數都設置爲 具有相同的值,以將光標移動到相應位置 而不選擇文本。
<?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>
https://developer.mozilla.org/en/XUL_Tutorial/Focus_and_Selection – linguini 2012-04-20 06:07:11