⑴ 怎麼在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標簽過濾掉就行了。