Skip to content

Instantly share code, notes, and snippets.

@shenqihui
Last active August 29, 2015 14:06
Show Gist options
  • Save shenqihui/5832b4a55388c874bd6e to your computer and use it in GitHub Desktop.
Save shenqihui/5832b4a55388c874bd6e to your computer and use it in GitHub Desktop.
escape any html tap. 转义部分tap
$('textarea')
.val()
.replace(/<([/^<>]*?((script)|(style)|(link)|(img)|(object)|(embed)|(textarea)|(input))[^<>]*?)>/g,"&lt;$1&gt;")
.replace(/\n/g,"<br>");
<textarea name="" id="" cols="30" rows="10">
<script>alert('测试');</script>
<img src="http://www.baidu.com/img/bd_logo.png" alt="">
<p>这是P标签</p>
<div>这是div标签</div>
<style>/*这个是style*/</style>
<link rel="stylesheet" href="http://www.baidu.com">
</textarea>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment