Javascript - Thay ký tự HTML
Viết một hàm JavaScript để thay ký tự HTML
Mã nguồn:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JavaScript program to convert the letters of a given string in alphabetical order.</title>
</head>
<script>
function escape_HTML(html_str) {
'use strict';
return html_str.replace(/[&<>"]/g, function (tag) {
var chars_to_replace = {
'&': '&',
'<': '<',
'>': '>',
'"': '"'
};
return chars_to_replace[tag] || tag;
});
}
document.write(escape_HTML('<a href="javascript-string-exercise-17.php" target="_blank">'));
</script>
<body>
</body>
</html>
Lưu đồ thuật toán:


