Convert HTML - Công Cụ chuyển HTML sang Kí Tự Đặc Biệt sẽ giúp các bạn mã hóa CODE sử dụng cho website.
Xin chào các bạn hôm nay megacode.vn sẽ hướng dẫn các bạn chuyển HTML sang kí tự đặc biệt bằng javascript đơn giản. Cái này có thể áp dụng cho việc mã hóa CODE sử dụng cho website.
<script type="text/javascript">
//<![CDATA[
function html2entities(){
var re=/[<>"'&]/g
for (i=0; i<arguments.length; i++)
arguments[i].value=arguments[i].value.replace(re, function(m){return replacechar(m)})
}
function replacechar(match){
if (match=="<")
return "<"
else if (match==">")
return ">"
else if (match=="\"")
return """
else if (match=="'")
return "'"
else if (match=="&")
return "&"
}
//]]>
</script>
<script type="text/javascript">
//<![CDATA[
//Character count script
function countit(what){
formcontent=what.form.charcount.value
what.form.displaycount.value=formcontent.length
}
//]]>
</script>
<form>
<textarea name="data1" style="width:100%; height: 200px;overflow:hidden; padding:10px;"></textarea>
<div class="separator" style="clear: both; text-align: center;">
<input name="button" type="button" class="abt2" onclick="html2entities(this.form.data1)" onmouseover="this.className='abt2 abt2hov'" onmouseout="this.className='abt2'" value="Convert">
<input onmouseover="this.className='abt3 abt3hov'" onmouseout="this.className='abt3'" class="abt3" name="Clear" value=" Clear " type="reset">
</div>
</form>
<div style="clear: both;"></div>
Chúc các bạn thành công.