jquery特殊字元過濾
① Jquery中的常用過濾器有哪些
1。$("#myDiv"); <div id="myDiv">id="myDiv"</div>(比較常用)
2。$("div");<div>DIV1</div>
3。$(".myClass"); <div class="myClass">div class="myClass"</div>(比較常用)
4。$("*") ;<div>DIV</div><span>SPAN</span><p>P</p> ...
5。$("div,span,p.myClass") ;<div>div</div><p class="myClass">p class="myClass"</p>
<span>span</span>
6。$("form input") ;<input name="name" />, <input name="newsletter" />(比較常用)
7.$("input[name='newsletter']").attr("checked", true); <input type="checkbox" name="newsletter" value="Hot Fuzz" checked="true" />, (比較常用)
前面是選擇器寫法,後面是得到的結果。
還有好多,一下想不起來。不過常用的就這些了。
② 如何利用jQuery post傳遞含特殊字元的數據
1、在$.ajax請求中新增參數:contentType:'application/json',對要傳遞的json數據作序列化JSON.stringify
2、將特殊字元串替換成特定字元,在後台再進行還原
③ js、jQuery如何過濾特殊字元(* 和/)
keyword=keyword.replace(/[\*\/]/g,"")
④ jQuery 過濾html標簽屬性的特殊字元
您好,如果在表單中需要提交一字元串,其中包含,< > " &字元時,當我們把這字元串顯示到jsp頁面時,會和html標簽產生沖突,導致web頁面的某些部分消失或者格式不正確。為了解決以上問題,需要在顯示之前,對字元串進行代碼過濾。
把字元串中的 < 替換為 &It;
> 替換為 >
" 替換為 "
& 替換為 &
這里給出一個靜態的過濾代碼,供大家參考:
public class StringUtils {
/**
* This method takes a string which may contain HTML tags (ie, <b>,
* <table>, etc) and converts the '<'' and '>' characters to their HTML escape sequences.
* @param input the text to be converted.
* @return the input string with the characters '<' and '>' replaced with their HTML escape sequences.
*/
public static final String escapeHTMLTags(String input) {
//Check if the string is null or zero length -- if so, return
//what was sent in.
if (input == null || input.length() == 0) {
return input;
}
//Use a StringBuffer in lieu of String concatenation -- it is
//much more efficient this way.
StringBuffer buf = new StringBuffer(input.length());
char ch = ' ';
for (int i = 0; i < input.length(); i++) {
ch = input.charAt(i);
if (ch == '<') {
buf.append("<");
}
else if (ch == '>') {
buf.append(">");
}else if(ch == '"'){
buf.append(""");
}else if(ch == '&'){
buf.append("&");
}
else {
buf.append(ch);
}
}
return buf.toString();
}
}
此時,只需在jsp中對字元串調用此方法(StringUtils.escapeHTMLTags(str))即可。
⑤ jquery的jqGrid插件,有沒有提供過濾的介面,類似filter("列名","過濾的字元串")
有的。來
http://trirand.com/blog/jqgrid/jqgrid.html
打開鏈自接後,左側菜單進入Searching ==>>Toolbar with Operations
⑥ jQuery關鍵輸入的關鍵字過濾table的代碼
var key=$('input ').val();
$('table tr').each(function(i,item){
if($(this).text().indexOf(key)>-1){
$(this).show();
}else
$(this).hide();
});
});
⑦ jquery去掉特殊符號,
直接原生JS的replace函數就行了,不需要jquery,jquery也沒這個功能函數
⑧ 如何用js或則jquery過濾特殊字元
1、jQuery使用正則匹配替換特殊字元
functionRegeMatch(){
varpattern=newRegExp("[~'!@#$%^&*()-+_=:]");
if($("#name").val()!=""&&$("#name").val()!=null){
if(pattern.test($("#name").val())){
alert("非法字元!");
$("#name").attr("value","");
$("#name").focus();
returnfalse;
}
}
}
2、jQuery限制輸入ASCII值
//數字0-9的ascii為48-57
//大寫A-Z的ascii為65-90
//小寫a-z的ascii為97-122
//----------------------------------------------------------------------
//<summary>
//限制只能輸入數字和字母
//</summary>
//----------------------------------------------------------------------
$.fn.onlyNumAlpha=function(){
$(this).keypress(function(event){
vareventObj=event||e;
varkeyCode=eventObj.keyCode||eventObj.which;
if((keyCode>=48&&keyCode<=57)||(keyCode>=65&&keyCode<=90)||(keyCode>=97&&keyCode<=122))
returntrue;
else
returnfalse;
}).focus(function(){
this.style.imeMode='disabled';
}).bind("paste",function(){
varclipboard=window.clipboardData.getData("Text");
if(/^(d|[a-zA-Z])+$/.test(clipboard))
returntrue;
else
returnfalse;
});
};
//-----調用方法$("#文本框id").onlyNumAlpha();
3、js正則匹配過濾
functionstripscript(s)
{
varpattern=newRegExp("[`~!@#$^&*()=|{}':;',\[\].<>/?~!@#¥……&*()——|{}【】『;:」「'。,、?]")
varrs="";
for(vari=0;i<s.length;i++){
rs=rs+s.substr(i,1).replace(pattern,'');
}
returnrs;
}
⑨ jquery 正則怎樣過濾所有
|$('#guolv').html().replace(/[ ]/g,"");//這句只替換
//測試:
"123 756werw wesd 33".replace(/[ ]/g,'')
//結果:"123756werwwed33"
$('#guolv').html().replace(/[ ]|s/g,"");//這句替換包括空白符
//測試:
"123 756werw wesd 33".replace(/[ ]|s/g,"")
//結果:"123756werwwed33"
若不能內滿足需求容請追問我
⑩ 正則表達式過濾特殊字元
正則表達式裡面你帶了逗號,應該這樣寫
[。~!@#$%\^\+\*&\\\/\?\|:\.<>{}()';="]
有些符號只有少數幾個符號需要轉義,而且不用打逗號,打了逗號就相當於把逗號也過濾掉了