下面的脚本将取代在文本区域中选择单词。但只能在IE中工作。知道如何使它工作在Firefox吗?(这个问题似乎在于(document.all) ?document.selection.createRange (): document.getSelection ();
<SCRIPT LANGUAGE="JavaScript">
<!--//
var seltext = null;
var repltext = null;
function replaceit()
{
seltext = (document.all)? document.selection.createRange() : document.getSelection();
var selit = (document.all)? document.selection.createRange().text : document.getSelection();
if (selit.length>=1){
if (seltext) {
repltext= prompt( Please enter the word to replace: , );
if ((repltext== )||(repltext==null)) repltext=seltext.text;
seltext.text = repltext;
window.focus()
}
}
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<form name="f">
<textarea cols= 40 rows= 10 name= msg ></textarea>
<input type="button" name="b" value="Replace" onClick="replaceit();">
</form>
</BODY>