사용자 도구

사이트 도구


javascript:commonfunctions

문서의 이전 판입니다!


Javascript Common Functions

Escape HTML

function escapeHtmlEntities (str) {
  if (jQuery !== undefined) {
    // Create an empty div to use as a container,
    // then put the raw text in and get the HTML
    // equivalent out.
    return jQuery('<div/>').text(str).html();
  }
 
  // No jQuery, so use string replace.
  return str
    .replace(/&/g, '&amp;')
    .replace(/>/g, '&gt;')
    .replace(/</g, '&lt;')
    .replace(/"/g, '&quot;')
    .replace(/'/g, '&#39;'); // Do not use "&apos;", IE does not support.
}
javascript/commonfunctions.1340615465.txt.gz · 마지막으로 수정됨: 2012/06/25 18:11 저자 kwon37xi