導航:首頁 > 凈水問答 > 獲取html過濾

獲取html過濾

發布時間:2022-01-22 06:16:11

⑴ 怎麼在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等代碼,如@

關鍵點制:

  1. 正則表達式,把要替換的內容用正則表達式表達出來,如字元串、數字、字母中文、標點符號等。

  2. 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標簽過濾掉就行了。

閱讀全文

與獲取html過濾相關的資料

熱點內容
水性漆廢水處理 瀏覽:166
雞蛋白醋製作半透膜 瀏覽:866
電離子去疣後如何護理吃啥葯 瀏覽:978
火腿加工廠熬肉廢水如何處理 瀏覽:777
大虎山鎮污水處理廠 瀏覽:684
蒸餾酒純喝 瀏覽:753
耐海水乙烯基酯樹脂 瀏覽:218
偉星前置凈水器哪個品牌好 瀏覽:745
豐田電瓶蒸餾水 瀏覽:797
丙烯酸廢水如何檢測 瀏覽:423
朗行汽車空調濾芯怎麼換 瀏覽:875
寶馬118i空氣濾芯在什麼位置 瀏覽:698
多倫伊利污水處理 瀏覽:842
凈水器ustoac是什麼意思 瀏覽:957
環氧樹脂玻璃鋼一布三塗 瀏覽:535
豆製品水處理設備 瀏覽:879
電熱水壺容易產生水垢 瀏覽:174
樹脂分離塔顯示界面低 瀏覽:78
眉縣污水管網工程項目 瀏覽:841
飲水機進入中國多少年了 瀏覽:145