⑴ 怎么在html读取过滤xml数据
<scripttype='text/javascript'>
loadXML=function(xmlFile){
varxmlDoc=null;
//判断浏览器的类型
//支持IE浏览器
if(!.DOMParser&&window.ActiveXObject){
varxmlDomVersions=['MSXML.2.DOMDocument.6.0','MSXML.2.DOMDocument.3.0','Microsoft.XMLDOM'];
for(vari=0;i<xmlDomVersions.length;i++){
try{
xmlDoc=newActiveXObject(xmlDomVersions[i]);
break;
}catch(e){
}
}
}
//支持Mozilla浏览器
elseif(document.implementation&&document.implementation.createDocument){
try{
/*document.implementation.createDocument('','',null);方法的三个参数说明
*第一个参数是包含文档所使用的命名空间URI的字符串;
*第二个参数是包含文档根元素名称的字符串;
*第三个参数是要创建的文档类型(也称为doctype)
*/
xmlDoc=document.implementation.createDocument('','',null);
}catch(e){
}
}
else{
returnnull;
}
if(xmlDoc!=null){
xmlDoc.async=false;
xmlDoc.load(xmlFile);
}
returnxmlDoc;
}
</script>
⑵ 怎样用js方法过滤html等代码,如@
关键点制:
正则表达式,把要替换的内容用正则表达式表达出来,如字符串、数字、字母中文、标点符号等。
replace() 方法,用于在字符串中用一些字符替换另一些字符,或替换一个与正则表达式匹配的子串。
上代码:
<html>
<head>
<title>无标题文档</title>
<metacharset="UTF-8">
</head>
<body>
<divid="main">文章内容@文章内容,文章内容@文章内容</div>
</body>
<script>
//获取标签中文本
vardoj_str=document.getElementById('main').innerText;
//要替换的字符串,最后的g表示全局匹配,例如又多个@
varreg_str=/@/g;
//替换为空
varnew_str=doj_str.replace(reg_str,'');
//输出新字符串
document.write(new_str);
</script>
</html>
⑶ 过滤html
你这个问题是一定能解决的。因为数据库出来的东西,在服务器端可以做任意的处理,其可能性是无限的。关键是,出来的是什么样的数据,你想要它是什么样的。有了具体的要求,才能作进一步的解答。
⑷ 正则表达式如何过滤HTML标签中的属性值
去掉html标签: str.replace(/</?[a-zA-Z]+[^><]*>/g,"")
去掉标签里面的属性: str.replace(/<([a-zA-Z]+)\s*[^><]*>/g,"<$1>")
我亲自测试通过,操作语言专javascript 楼主还有问题的属话Hi 我
⑸ jquery获取html值过滤空格
|var r = "asldfkjl lasdjfl <br /> sdfjlk <br/> ; ; ; ;"<br>alert(r.replace(/(<br[^>]*>| |\s*)/g,''));<br>首先应该替换成html能识别的,然后版再进行权获取
⑹ 过滤所有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等代码
^<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>
⑻ 用正则表达式过滤获取到的HTML,取得HTML里其中的一段代码
function returnHtml(){
var str = "123<ul class=\"list01 font_s_14 line_h_25\">456</span></li></ul><div class=\"box_hr16\">";
var res = str.replace(/<ul class=\"list01 font_s_14 line_h_25\">(.*)</span></li></ul><div class=\"box_hr16\">/,"");
if(!res||res[1])
return "";
return res[1];
}
⑼ 怎么过滤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;
}
⑽ 如何过滤HTML标签,或者读取数据时,去处HTML标签
如果你把html标签除掉了问题会更大。
如果你不需要所见即所得的编辑器,那么可以直接使用textarea。在把用户输入的html标签过滤掉就行了。