Convert HTML Entities

function convert(str) {

    var arr1 = ['&','<','>','"',"'"];

     var arr2 = ['&','<','>','"','''];

    var reg = /[&<>"']/g;

    var regArr = str.match(reg);

    if(regArr){

     for(var i=0;i

         str = str.replace(arr1[arr1.indexOf(regArr[i])],arr2[arr1.indexOf(regArr[i])]);

    }

      return str;

      }

return str;

你可能感兴趣的:(Convert HTML Entities)