jshtml過濾
『壹』 如何用javascript過濾用戶輸入的<,>,",'
可以用正則過濾一下.
<body>
<input type="text" onpropertychange="javascript:var tstr=this.value.replace(/[<>'\x22]/g,'');if(tstr!=this.value)this.value=tstr;">
</body>
『貳』 如下代碼,如何將內容中的html過濾掉。Content內容
讓我來猜猜看,你是不是需要這個。 Function RemoveHTML(strHTML) Dim objRegExp, Match, Matches Set objRegExp = New Regexp objRegExp.IgnoreCase = True objRegExp.Global = True '取閉合的<> objRegExp.Pattern = "<.+?>" '進行匹配 Set Matches = objRegExp.Execute(strHTML) ' 遍歷匹配集合,專並替換掉匹屬配的項目 For Each Match in Matches strHtml=Replace(strHTML,Match.Value,"") Next RemoveHTML=strHTML Set objRegExp = Nothing End Function
『叄』 怎麼過濾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等代碼
^<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如何實現過濾""的輸入
在javascript和java中,可以用轉義字元\"來達到輸入"的目的。
『陸』 如何過濾HTML的標簽
這個很簡單的,一般後台向前端傳輸數據的時候都要經過相關的轉移和二者是相關的處理。將h t ml代碼轉換成字元串兒不讓瀏覽器解析。
『柒』 怎麼使用js過濾html標簽
你可以利用正則表達式來剔除這些標簽,也就是將所有的html類的標簽都替換為空即可:
//去除HTML標簽
str=str.replace(/</?[^>]*>/g,'');
『捌』 JS正則過濾指定的HTML標簽
^1,得到網頁上的鏈接地址:
string
matchString =
@"<a[^>]+href=\s*(?:'(?<href>[^']+)'|""(?<href>[^""]+)""|(?<href>[^>\s]+))\s*[^>]*>";
2,得到網頁的標題回:
string matchString = @"<title>(?<title>.*)</title>";
3,去掉網頁中的所有的答html標記:
string temp = Regex.Replace(html, "<[^>]*>", ""); //html是一個要去除html標記的文檔
4, string matchString = @"<title>([\S\s\t]*?)</title>";
5,js去掉所有html標記的函數:
function delHtmlTag(str)
{
return str.replace(/<[^>]+>/g,"");//去掉所有的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的標題
^1,得到網頁上的鏈接地址:
string
matchString =
@"<a[^>]+href=\s*(?:'(?<href>[^']+)'|""(?<href>[^""]+)""|(?<href>[^>\s]+))\s*[^>]*>";
2,得到網頁的標題:
string matchString = @"<title>(?<title>.*)</title>";
3,去掉網頁中的所有的html標記:
string temp = Regex.Replace(html, "<[^>]*>", ""); //html是一個要去除html標記的文檔
4, string matchString = @"<title>([\S\s\t]*?)</title>";
5,js去掉所有html標記的函數:
function delHtmlTag(str)
{
return str.replace(/<[^>]+>/g,"");//去掉所有的html標記
}