$search = array ("'<script[^>]*?>.*?</script>'si", // 去掉 JavaScript
"'<[\/\!]*?[^<>]*?>'si", // 去掉 HTML 标记
"'([\r\n])[\s]+'",// 去掉空白字符
"'&(quot|#34)'i",// 替换 HTML 实体
"'&(amp|#38)'i",
"'&(lt|#60)'i",
"'&(gt|#62)'i",
"'&(nbsp|#160)'i"
) // 作为 PHP 代码运行
$replace = array ("","","\\1","\"","&","<",">"," ")
$html = preg_replace($search, $replace, $html)
顶
<!DOCTYPE html><html lang="en">
<head>
<meta charset="UTF-8">
<title>test</title>
<script type="text/javascript">
window.onload = function() {
var oTxt1 = document.getElementById('txt1')
var oTxt2 = document.getElementById('txt2')
var test = document.getElementById('test')
test.onclick = function() {
var reg = /<[^<>]+>/g
oTxt2.value = oTxt1.value.replace(reg, '')
}
}
</script>
</head>
<body>
<div>
<input type="text" id="txt1">
<input type="text" id="txt2">
</div>
<div><button id="test">测试</button></div>
</body>
</html>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)