如果只选择了一个字符,range.extractContents()有时只会只选择innerHTML整个文档片段

时间:2018-08-01 19:20:03

标签: javascript jquery html

我有一些文本可供用户选择,例如:

program Project3;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils, System.Classes, System.JSON.Builders, System.JSON.Readers, System.JSON.Types;

const JsonStr = '{' +
'   "result":{     ' +
'      "elements":[   ' +
'         {              ' +
'            "id":"ML_1HMloeUjEFgKaC9",' +
'            "name":"Utilization Survey",' +
'         },' +
'         {' +
'            "id":"ML_1zQjGtGXFPkEo6N",' +
'            "name":"Training Seminar - Nov 9",' +
'         }' +
'      ]' +
'   },' +
'   "meta":{' +
'      "httpStatus":"200 - OK",' +
'      "requestId":"ef2afd6e-3fd9-4fdf-a8fe-c935c147a0af"' +
'   }' +
'}';

procedure RunIt;
var Reader : TJsonTextReader;
  Iterator : TJsonIterator;
  StringReader : TStringReader;
  Found : Boolean;
begin
  StringReader := TStringReader.Create(JsonStr);
  Reader := TJsonTextReader.Create(StringReader);
  Iterator := TJsonIterator.Create(Reader);
  try
    Found := Iterator.Find('result["elements"][?(@.name == ''Training Seminar - Nov 9'')]');
    //The value of Found is false or an exception is raised because of bad syntax in the filter expression
    WriteLn(BoolToStr(Found));
    ReadLn;
  finally
    Iterator.Free;
    Reader.Free;
    StringReader.Free;
  end;
end;

begin
  try
    RunIt;
  except
    on E: Exception do
    begin
      Writeln(E.ClassName, ': ', E.Message);
      Readln;
    end
  end;
end.

当用户选择字符'e'时,有时extractContents方法仅返回innerHTML'e',而不是<span onmouseup="top.onMouseUpEssence('534','');" name="534">h</span> <span onmouseup="top.onMouseUpEssence('534','');" name="534">e</span> <span onmouseup="top.onMouseUpEssence('534','');" name="534">r</span> <span onmouseup="top.onMouseUpEssence('534','');" name="534">e</span>

这是我的代码:

<span onmouseup="top.onMouseUpEssence('534','');" name="534">e</span>

有人知道为什么吗?谢谢。

0 个答案:

没有答案