English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

JS 및 JQuery로 Html 내용 인코딩, Html 인코딩

말이 많지 않습니다. 코드를 보세요:

 /** JQuery Html 인코딩, 디코딩 
* 원리는 JQuery가 내장한 html()과 text() 함수를 통해 Html 문자를 변환할 수 있다는 것입니다 
* 가상의 Div를 할당하고 값을 가져와 원하는 Html 인코딩이나 디코딩을 얻을 수 있습니다 
*/ 
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script> 
<script type="text/javascript"> 
//Html 인코딩을 통해 Html 변환 엔티티 가져오기 
function htmlEncode(value){ 
 return $('<div/>').text(value).html(); 
} 
//Html 디코딩을 통해 Html 엔티티 가져오기 
function htmlDecode(value){ 
 return $('<div/>').html(value).text(); 
} 
</script> 
<script type="text/javascript"> 
//Html 변환 문자 가져오기 
function htmlEncode( html ) {}} 
 return document.createElement( 'a' ).appendChild( 
  document.createTextNode( html ) ).parentNode.innerHTML; 
}; 
//getHtml 
function htmlDecode( html ) { 
 var a = document.createElement( 'a' ); a.innerHTML = html; 
 return a.textContent; 
}; 
</script> 
//encoded 
 function html_encode(str) 
 { 
 var s = ""; 
 if (str.length == 0) return ""; 
 s = str.replace(/&/g, ">"); 
 s = s.replace(/</g, "<"); 
 s = s.replace(/>/g, ">"); 
 s = s.replace(/ /g, " "); 
 s = s.replace(/'/g, "'"); 
 s = s.replace(/\"/g, """); 
 s = s.replace(/\n/g, "<br>"); 
 return s; 
 } 
 //decoded 
 function html_decode(str) 
 { 
 var s = ""; 
 if (str.length == 0) return ""; 
 s = str.replace(/>/g, "&"); 
 s = s.replace(/</g, "<"); 
 s = s.replace(/>/g, ">"); 
 s = s.replace(/ /g, " "); 
 s = s.replace(/'/g, "\'"); 
 s = s.replace(/"/g, "\""); 
 s = s.replace(/<br>/g, "\n"); 
 return s; 
 } 

이것이 본 문서의 전체 내용입니다. 본 문서의 내용이 여러분의 학습이나 업무에 도움이 되길 바랍니다. 또한, 노래 강의에 많은 지원을 부탁드립니다!

언급: 본 내용은 인터넷에서 가져왔으며, 저작권자는 본 사이트에 소유되어 있지 않으며, 인터넷 사용자가 자발적으로 기여하고 업로드한 내용입니다. 본 사이트는 소유권을 가지지 않으며, 인공적인 편집을하지 않았으며, 관련 법적 책임을 부담하지 않습니다. 저작권 문제가 있음을 발견하면 notice#w로 이메일을 보내 주시기 바랍니다.3codebox.com에 이메일을 보내면(#을 @으로 변경해야 합니다) 신고를 해 주시고 관련 증거를 제공해 주시면, 해당 내용이 사실이 되면 즉시 해당 내용을 제거할 것입니다.