finddialog.js

来自「CallSun 人才招聘求职系统 V2.20」· JavaScript 代码 · 共 74 行

JS
74 行
字号
// JScript 文件
var EditorFrame = window.dialogArguments;
var FindRange = EditorFrame.document.body.createTextRange();
function Find(direction)
{
    var bFound = false;
    var TextFind = document.getElementById("TextFind");
    if (TextFind.value == "")
    {
        alert("请输入要查找的内容");
    }
    else
    {
	    var iFlags = 0 ;

	    if ( ChkCase.checked )
		    iFlags = iFlags | 4 ;

	    if ( ChkWord.checked )
		    iFlags = iFlags | 2 ;

	    bFound = FindRange.findText(TextFind.value, direction, iFlags ) ;

	    if (bFound)
	    {
		    FindRange.scrollIntoView() ;
		    FindRange.select() ;
		    FindRange.collapse(false) ;
	    }
	    else
	    {
		    FindRange = EditorFrame.document.body.createTextRange();
	    }
	}
	return bFound;
}

function Replace()
{
    Find(0);
    if (EditorFrame.document.selection != null)
    {
        var selectedtext = EditorFrame.document.selection.createRange().text;
        if (selectedtext.length > 0)
        {
            if (selectedtext != document.getElementById("TextFind").value)
            {
                FindRange = EditorFrame.document.body.createTextRange();
            }
            EditorFrame.document.selection.createRange().text = document.getElementById("TextReplace").value;
        }
    }
    Find(1);
}

function ReplaceAll()
{
    FindRange = EditorFrame.document.body.createTextRange();
    var count = 0;
    while(Find(1))
    {
        count++;
        EditorFrame.document.selection.createRange().text = document.getElementById("TextReplace").value;
    }
    if (count > 0)
    {
        alert("操作完成,共完成替换" + count + "处内容");
    }
    else
    {
        alert("操作失败,未找到任何待替换数据");
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?