功能背景:将敏感字替换为 * 或其它符号
具体实现:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<textarea name="" id="" cols="30" rows="10"></textarea>
<button>发送</button>
<div></div>
<script>
var text = document.querySelector('textarea');
var but = document.querySelector('button');
var div = document.querySelector('div');
but.onclick = function(){
div.innerHTML = text.value.replace(/s|大/g,'*');
}
</script>
</body>
</html>
当信息中出现“ 大 ”字的时候,就会将这个字替换为 *
以上就是本章的全部内容,感谢您在阅读。