日期:2014-05-16  浏览次数:20392 次

js 禁用脚本和过滤大小括号

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>word-break</title> 
<script type="text/javascript" src="jquery-1.4.2.js"></script>
<script type="text/javascript">
		$(function(){
			//不过滤A标签;并放到三个标签里面
			$("#displayPage").click(function(){
					var text=$(".pre").text();
					$("#xm").text(text);
					$("#xp").text(text);
					$("#xd").text(text);
					
					
				
			});
			//不过滤A标签
			$("#queryTextarea").click(function(){
				var text=$(".pre").text();
				$("#txt1").text(text);
			}); 
			//过滤A标签
			$("#filterA").click(function(){
				var html=$(".pre").html();
				
				html=html.replaceAll("&lt;","<");	//左边括号
				html=html.replaceAll("&gt;",">");	//右边括号
				html=html.replaceAll("&nbsp;"," ");	//过滤空格
				
				$("#txt2").text(html);
			});
			
		
		
		String.prototype.replaceAll = function(s1, s2) {    
			return this.replace(new RegExp(s1, "gm"), s2); //g全局   
		}   
		  
		String.prototype.replaceAll2Excep = function(s1, s2) {      
			var temp = this;      
			while (temp.indexOf(s1) != -1) {      
				temp = temp.replace(s1, s2);      
			}      
			return temp;      
		}    
		
			
		});
		</script>
<style>
	.pre{
width:100px;
border:1px solid #99bbe9;
white-space: pre-wrap;  //控制长度    
white-space: -moz-pre-wrap; 
white-space: -pre-wrap;     
white-space: -o-pre-wrap;   
word-wrap: break-word;       //换行断词 warp换行的意思
word-break:break-all;       //断英文词
//
float:left;
}
</style>

<body>
<button id="displayPage">放到页面上不过滤A标签</button>
<button id="queryTextarea">放到textarea的值不过滤A标签</button>
<button id="filterA">放到textarea的值过滤A标签</button><br/>
原码
<pre class="pre">
&lt;html&gt;
&lt;head&gt;
  &lt;script type=&quot;text/javascript&quot; src=&quot;loadxmldoc.js&quot;&gt;
&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;

  &lt;script type=&quot;text/javascript&quot;&gt;
    xmlDoc=<a href="dom_loadxmldoc.asp">loadXMLDoc</a>(&quot;books.xml&quot;);
    document.write(&quot;xmlDoc is loaded, ready for use&quot;);
  &lt;/script&gt;

&lt;/body&gt;
&lt;img src="http://www.baidu.com/img/baidu_jgylogo3.gif" /&gt;


&lt;/html&gt;&nbsp;aa

</pre>>------------------------------------xmp<br/>
<xmp id="xm"></xmp>------------------------------------pre
<pre id="xp"></pre>>------------------------------------div
<div id="xd"></div>
不过滤A标签;检查英文字符<textarea style="width:500px;height:500px" id="txt1" ></textarea><br/>
过滤A标签;不检查英文字符<textarea style="width:500px;height:500px" id="txt2" spellcheck="false"></textarea>

</body> 
</html>
?