2016-12-15 10 views
0

견인을 찾으려고 노력하고 있어요 innerhtml 안에 여러 가지 texttypes, 어떻게 든 그것은 아무것도 찾을 수 없습니다하지만 내가 같은 기능과 테스트 샘플과 함께 그것을 테스트 할 때 작동합니다.자바 스크립트 innerHtml을 통해 검색 할 수 없습니다

function numberoftext (a){if (a.match(/class=\"chattext\"/g)!==null){return a.match(/class=\"chattext\"/g).length;}else{return 0;}} 
function numberofglobal (a){if (a.match(/class=\"chattextglobal\"/g)!==null){return a.match(/class=\"chattextglobal\"/g).length;}else{return 0;}} 
function numberofclan (a){if (a.match(/class=\"chattextclan\"/g)!==null){return a.match(/class=\"chattextclan\"/g).length;}else{return 0;}} 
function numberofgroup (a){if (a.match(/class=\"chattextgroup\"/g)!==null){return a.match(/class=\"chattextgroup\"/g).length;}else{return 0;}} 
function numberofwisper (a){if (a.match(/class=\"chattextwhisper\"/g)!==null){return a.match(/class=\"chattextwhisper\"/g).length;}else{return 0;}} 
function numberofworld (a){if (a.match(/class=\"worldsay\"/g)!==null){return a.match(/class=\"worldsay\">/g).length;}else{return 0;}} 
function numberofscream (a){if (a.match(/class=\"chattextscream\"/g)!==null){return a.match(/class=\"chattextscream\"/g).length;}else{return 0;}} 
var innertextraw1 =chatupdateFrame.document.documentElement.innerHTML; 
var innertextraw= innertextraw1.substring(innertextraw1.indexOf("parent.chattextFrame.add(")+26, innertextraw1.indexOf("', 0);")); 

console.log("got update",innertextraw); 
console.log("t:",numberoftext(innertextraw),"c:",numberofclan(innertextraw),"w:",numberofwisper(innertextraw),"gr:",numberofgroup(innertextraw),"gl:",numberofglobal(innertextraw),"sc:",numberofscream(innertextraw)); 

는 innertextraw에 대한 예는 다음과 같습니다 "<p class=\"chattext\"><i><b>noone</b> goes with <b>someone</b> to the house</i></p>" 내가 콘솔 로그에서 가져온 예에 innertextraw 설정도 할 때 that처럼 테스트를하는 것은 잘 작동, 웹 사이트에 그냥 0

답변

1

를 반환하면 문자열의 이스케이프 된 따옴표와 일치 시키려면 " 따옴표를 이스케이프 처리하지 않아도됩니다. 진짜 문자열에서

a.match(/class="chattext"/g) 

는 그 탈출 슬래시는 실제로 존재하지 않는, 문자열이 구분 기호로 그 문자를 사용하는 경우 리터럴 더블 (또는 단일) 견적을 대표하는 단지 방법이 없다, 그래서 당신은에 있습니다 그것을 피하십시오.

var innerRawText = "<p class=\"chattext\"><i><b>noone</b> goes with <b>someone</b> to the house</i></p>"; 
 

 
var result = innerRawText.match(/class="chattext"/g); 
 
console.log(result);

: 여기

는 작업 예제