㈠ js如何过滤div内某特定HTML标签
//这里为了方便使用jQuery
//移除使用tag类的div标记下的strong标记下a标记下没有子回元素(链接为空答)的节点元素
jQuery('div.tagstronga:empty').parent().remove();
㈡ 过滤所有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>
㈢ 怎么使用js过滤html标签
你可以利用正则表达式来剔除这些标签,也就是将所有的html类的标签都替换为空即可:
//去除HTML标签
str=str.replace(/</?[^>]*>/g,'');
㈣ 怎样用js方法过滤html等代码
^<input type="text" id="theOne" value="">
<input type="button" onclick="NoHtml()" value="过滤html标签">
<script>
function NoHtml(){
var t=document.getElementById("theOne").value;
t=t.replace(/({|})/g,''); //过滤{}
t=t.replace(/</g,'<'); //置换符号<
t=t.replace(/>/g,'>'); //置换符号>
// t=t.replace(/<\/?[^>]*>/g,''); //*<\/?[^>]*>可以匹配<script></style></body>等,并置空。而不是替内换容<和>两个符号
document.getElementById("theOne").value=t;
}
</script>
㈤ 怎样屏蔽用户输入的javascript或指定的html标签
其实你只需要转换 <> 这两个符号
/// <summary>
/// 转换成 HTML code
/// </summary>
/// <param name="str">string</param>
/// <returns>string</returns>
public static string Encode(string str)
{
str = str.Replace("&"," & a m p;");
str = str.Replace("'","''");
str = str.Replace("\"","& q u o t;");
str = str.Replace(" ","& n b s p;");
str = str.Replace("<","& l t;");
str = str.Replace(">","& g t;");
str = str.Replace("\n","< b r>");
return str;
}
因为网络显示的问题 我空了格
㈥ JavaScript用正则表达式过滤 html 标签
1:content=content.replace(/<\/?p[^>]*>/gi,'');//删除所有的<p>及</p>标签
2:content=content.replace(/<p[^>]*>/gi,'').replace(/<\/p>/gi,'<br />');
㈦ 如何使用js正则 过滤某一个html标签下所有的标签跟样式呢只保留出纯文本
js过滤标签的方法。分享给大家供大家参考,具体如下:
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/>
<title>无标题文档</title>
<script>
window.onload=function()
{
varoTxt1=document.getElementById('txt1');
varoTxt2=document.getElementById('txt2');
varoBtn=document.getElementById('btn');
oBtn.onclick=function()
{
varreg=/<[^<>]+>/g;
oTxt2.value=oTxt1.value.replace(reg,'');
};
};
</script>
</head>
<body>
<textareaid="txt1"cols="40"rows="10"></textarea><br/>
<inputtype="button"value="过滤"id="btn"/><br/>
<textareaid="txt2"cols="40"rows="10"></textarea>
</body>
</html>
㈧ 怎么过滤html标签
过滤html标签代码如下:
public string checkStr(string html)
{
System.Text.RegularExpressions.Regex regex1 = new System.Text.RegularExpressions.Regex(@"<script[\s\S]+</script *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex2 = new System.Text.RegularExpressions.Regex(@" href *= *[\s\S]*script *:", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex3 = new System.Text.RegularExpressions.Regex(@" on[\s\S]*=", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex4 = new System.Text.RegularExpressions.Regex(@"<iframe[\s\S]+</iframe *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex5 = new System.Text.RegularExpressions.Regex(@"<frameset[\s\S]+</frameset *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex6 = new System.Text.RegularExpressions.Regex(@"\<img[^\>]+\>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex7 = new System.Text.RegularExpressions.Regex(@"</p>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex8 = new System.Text.RegularExpressions.Regex(@"<p>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex9 = new System.Text.RegularExpressions.Regex(@"<[^>]*>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
html = regex1.Replace(html, ""); //过滤<script></script>标记
html = regex2.Replace(html, ""); //过滤href=javascript: (<A>) 属性
html = regex3.Replace(html, " _disibledevent="); //过滤其它控件的on...事件
html = regex4.Replace(html, ""); //过滤iframe
html = regex5.Replace(html, ""); //过滤frameset
html = regex6.Replace(html, ""); //过滤frameset
html = regex7.Replace(html, ""); //过滤frameset
html = regex8.Replace(html, ""); //过滤frameset
html = regex9.Replace(html, "");
html = html.Replace(" ", "");
html = html.Replace("</strong>", "");
html = html.Replace("<strong>", "");
return html;
}
㈨ 怎么让js过滤html标签
|代码袭如下:
function removeHTMLTag(str) {
str = str.replace(/<\/?[^>]*>/g,''); //去除HTML tag
str = str.replace(/[ | ]*\n/g,'\n'); //去除行尾空白
//str = str.replace(/\n[\s| | ]*\r/g,'\n'); //去除多余空行
str=str.replace(/ /ig,'');//去掉
return str;
}
㈩ html标签过滤的js代码没法使用
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* <p>
* Title: HTML相关的正则表达式工具类
* </p>
* <p>
* Description: 包括过滤HTML标记,转换HTML标记,替换特定HTML标记
* </p>
* <p>
* Copyright: Copyright (c) 2006
* </p>
*
* @author hejian
* @version 1.0
* @createtime 2006-10-16
*/
public class HtmlRegexpUtil {
private final static String regxpForHtml = "<([^>]*)>"; // 过滤所有以<开头以>结尾的标签
private final static String regxpForImgTag = "<\\s*img\\s+([^>]*)\\s*>"; // 找出IMG标签
private final static String regxpForImaTagSrcAttrib = "src=\"([^\"]+)\""; // 找出IMG标签的SRC属性 这个是java代码吧 需要运行在java虚拟机中。