function testpassfail(jobid){
var data;
$.ajax({
url: '/getJobReport?jobid=' + jobid,
async: false,
}).done(function (report) {
if(report) {
for(var browser in report) {
data = report[browser].result || '';
data = data.replace(/\n/g, '<br />');
data = data.replace(/Passed/g, '<span class="pass">Passed</span>');
data = data.replace(/Failed/g, '<span class="fail">Failed</span>');
}
}
});
alert(data);//Checking button: Ok<br />Selecting ff: <span class="fail">Failed</span><br />Test <span class="fail">Failed</span><br />
return data;
}
我的数据数据打印
data='Checking button: Ok<br />Selecting ff: <span class="fail">Failed</span><br />Test <span class="fail">Failed</span><br />'
从中我如何获得最后的数据Test <span class="fail">Failed</span><br />
答案 0 :(得分:1)
试试此代码
var data='Checking button: Ok<br />Selecting ff: <span class="fail">Failed</span><br />Test <span class="fail">Failed</span><br />';
var array_fragment = data.split('<br />');
var result = array_fragment[array_fragment.length - 2];
这将返回Test <span class="fail">Failed</span>
如果您需要Test <span class="fail">Failed</span><br />
,请使用<br />
finalResult=result+'<br />';
以下是Fiddle