js中直接对字符串转义-用于solr ulr 关键词转义
生活随笔
收集整理的這篇文章主要介紹了
js中直接对字符串转义-用于solr ulr 关键词转义
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
js代碼
/*
?* 獲取UTC格式的字符串,參數(shù)必須是
?*/
var solrDateFormat = function (o){
?? ?var date;
?? ?if(typeof o == 'string'){
?? ??? ?date = new Date(o);
?? ?}else if(o instanceof Date){
?? ??? ?date = o;
?? ?}else{
?? ??? ?return '';
?? ?}
?? ?return date.getUTCFullYear() + '-' + (date.getUTCMonth() + 1) + '-'
?? ?+ date.getUTCDate() + 'T' + date.getUTCHours() + ':'
?? ?+ date.getUTCMinutes() + ':' + date.getUTCSeconds() + 'Z';
};
/** 轉義字符查詢*/ var escapeQueryChars = function (q){var result = '';//如果字符串q 不為空(null,未定義,空)if (q !== null && q !== undefined && q !== '' && q !=="") {for(var i=0;i < q.length;i++){var c = q.charAt(i);if (c == '\\' || c == '+' || c == '-' || c == '!' || c == '(' || c == ')' || c == ':'|| c == '^' || c == '[' || c == ']' || c == '\"' || c == '{' || c == '}' || c == '~'|| c == '*' || c == '?' || c == '|' || c == '&' || c == ';' || c == '/'|| c == ' ') {result = result+ '\\';} result = result+ c;}}else{return "*:*";}return result; };
測試:
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <script type="text/javascript" src="js/jquery-1.7.2.min.js"></script> <script type="text/javascript" src="json3/produce/json3.min.js"></script> <script type="text/javascript" src="js/myUtil.js"></script> <script type="text/javascript">//var date = new Date("2013/9/29 11:10:26");//console.info(solrDateFormat(date));//console.info(solrDateFormat("2013/9/29 11:10:26"));//console.info(solrDateFormat("2013/09/29 21:10:26"));// 測試 escapeQueryChars方法var q = "天翼大眾 (1)";alert(escapeQueryChars(q)); </script> <title>搜索測試</title> </head> <body><div><input id="keyword" type="text"> <input id="search" type="button"value="search" ></div><div id="result"></div> </body> </html>
?
轉載于:https://www.cnblogs.com/a198720/p/4466826.html
總結
以上是生活随笔為你收集整理的js中直接对字符串转义-用于solr ulr 关键词转义的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 计组之存储系统:5、cache(cach
- 下一篇: (王道408考研操作系统)第三章内存管理