JavaScript Tutorials Filter HTML tag code
<head>
<meta http-equiv= "Content-type" content= "HTML; charset=gb2312 "/>
<title>javascript Tutorial Filters HTML Tag Code </title>
<script language= "JavaScript" >
<!--
function SetContent () {
var obj = document.getElementById (' code ');
Obj.value = Obj.value.replace (/</?[ ^>]*>/g; Remove HTML tag
Obj.value = Obj.value.replace (/[|) *n/g, ' n '); Remove line trailing blanks
Obj.value = Obj.value.replace (/n[s| |) *r/g, ' n '); Remove extra blank lines
alert (Obj.value);
}
var str = "<b> 1111 <u> 2222 <i> 3333 </i> </u> </b>";
str = str.replace (/<[^>]+> G, "");
str = str.replace (/< (. *) >. * </1>/, "");
alert (str);
function SetContent (str) {
str = str.replace (/</?[ ^>]*>/g; Remove HTML tag
Str.value = str.replace (/[|) *n/g, ' n '); Remove line trailing blanks
str = str.replace (/n[s| |) *r/g, ' n '); Remove extra blank lines
return str;
}
<!--
str = "<a href=" xxx.asp tutorial ">123456789</a>";
Alert (Str.replace/<a.*?> (. *?) </a>/ig, "$");
-->
-->
</script>
</head>
<body>
</body>
</html>