Bootstrap

html获得字符串里有标签,获取HTML字符串中的特定标签

var txt= "Inhib] ${name}$${product1}$${produ4ct28}$[空$换行]${Revies}$[空行]Cou${product9}$p}o";

txt= txt.replace(/\r\n|\r|\n/g,'[换行]').replace(/\s/g,'[空]');

function resolveHTML(html){

var myArr = new Array();

var tag = 0;

var val = '';

for (var i=0;i

if(html.charAt(i) == '$' || tag >0){

// alert(val+' '+tag+' '+html.charAt(i));

if(tag == 4){

tag = 0;val = '';

}

if(tag == 1 && html.charAt(i) != '{'){

tag = 0;val = '';

}

if(tag == 3 && html.charAt(i) != '$'){

tag = 0;val = '';

}

if(html.charAt(i) == '$' && tag == 0){

val += html.charAt(i);

tag = 1;

}

if(html.charAt(i) == '{' && tag == 1){

val += html.charAt(i);

tag = 2;

}

if(html.charAt(i) != '{' && html.charAt(i) != '}' && tag == 2){

val += html.charAt(i);

}

if(html.charAt(i) == '}' && tag == 2){

val += html.charAt(i);

tag = 3;

}

if(html.charAt(i) == '$' && tag == 3){

val += html.charAt(i);

tag = 4;

myArr[myArr.length]= val;

}

}

}

return myArr;

}

var html = '';

var myArr = resolveHTML(txt);

var methed = '';

var arg = 0;

for(var i=0;i

html+= '标签名称: ';

methed = 'Get'+myArr[i].replace('${','').replace('}$','');

arg = methed.replace(/[^0-9]/ig,"");

if(/^(\-?)(\d+)$/.test(arg)){methed = methed.replace(arg,'');}else{arg=i;};

html+= '方法名称: ';

html+= '方法参数:
';

}

document.write(html);

;