1

iframeに特定のテキストキーワードが含まれているかどうかを確認し、それを表示/表示するにはどうすればよいですか...?

ocr iframeには動的に生成されたテキストが含まれるため、特定の部分を取得する必要があります

私が持っているコードは機能しません:

    <iframe id="ocr"></iframe>

    $('#ocr:contains("keyword")').addClass("highlight");

    if ($('#ocr').text().indexOf("keyword") != -1){alert('found keyword');}
4

2 に答える 2

0
$("#ocr").highlightTextarea({
words: ["\\B@\\w+"],
color: "lightblue",
id: "mark"
});

http://jsfiddle.net/sQVe/uhHnN/3/

このようなものを試してみてください...

于 2013-02-09T15:14:47.173 に答える
0

You need to analyse the contents of the iframe, not just the iframe element itself. You can use contents().

For example:

if($("#ocr").contents().find('body').text().indexOf("keyword") != -1)
{
    alert('Keyword found');
}
于 2013-02-09T15:48:26.750 に答える