/** * Created by 炜文 on 2017/2/15. */ var intext = '485222<script> var i=2;var j=2;console.log(i+j)</script>this is a script' execScripts =function (intext) { var si=0; while (true){ var ss = intext.indexOf("<"+"script"+">",si); if (ss==-1){ return; } var se = intext.indexOf("<"+"/"+"script"+">",ss); if (se==-1){ return; } si = se + 9; var sc = intext.substring(ss+8,se); eval(sc); } } execScripts(intext);