<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
// 1、将字符串”<tr><td>{$id}</td><td>{$name}</td></tr>”中的
// {$id}替换成 10,{$name}替换成 Tony (使用正则表达式)
var str = "<tr><td>{$id}</td><td>{$name}</td></tr>";
res = str.replace(/\{\$id\}/g, "<10>").replace(/\{\$name\}/g, '<Tony>');
console.log(res)
// 2、为了保证页面输出安全,我们经常需要对一些特殊的字符进行转义,
// 请写一个函数 escapeHtml,将<, >, &, “进行转义”
function escapeHtml(input){
return input.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
}
console.log(escapeHtml(`&,<,>`));
</script>
</body>
</html>