導航:首頁 > 凈水問答 > html標簽過濾javascript

html標簽過濾javascript

發布時間:2021-10-26 12:46:51

㈠ 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虛擬機中。

閱讀全文

與html標簽過濾javascript相關的資料

熱點內容
益方泉凈水機多少錢一台 瀏覽:817
污水直排的情況進行全面整治 瀏覽:182
順達貨車空調濾芯在哪裡 瀏覽:129
城市污水處理廠污泥氰化物 瀏覽:545
污水流入消費者的主要形式 瀏覽:659
凈水器反滲透上型號怎麼看 瀏覽:866
粉末活性炭廢水 瀏覽:779
反滲透膜ge 瀏覽:594
企業污水排污費計算公式 瀏覽:507
立升凈水機哪個型號好 瀏覽:488
適合做反滲透膜的聚碸 瀏覽:536
純水機買多少加侖的 瀏覽:550
雪佛蘭樂風濾芯是什麼規格 瀏覽:76
熱水器排污水的鍾有什麼作用 瀏覽:449
硬挺樹脂廠家 瀏覽:83
智能馬桶濾芯怎麼看是否換 瀏覽:208
文昌污水處理項目epc 瀏覽:106
水的去離子度 瀏覽:874
女式摩托車濾芯在什麼位置 瀏覽:337
魚便堵在水泵過濾口 瀏覽:814