jq获取文件后缀的方法
var file = "测试文档1111111111.docx" ; // 文件
var fileName = file.replace( /.*( \/| \\) /, "" ) ; // 获得文件名
var fileSuffix = ( /[ .] /.exec( fileName)) ? /[ ^.] +$/.exec( fileName.toLowerCase( )) : '' ; // 获得文件后缀
var file = "测试文档1111111111.docx" ;
var dot = file.lastIndexOf( "." ) ;
var type = file.substr( dot) ;
var fileSuffix = "" ;
if( type == = ".jpg" || type == = ".gif" || type == = ".JPG" || type == = ".GIF" || type == = ".pdf" || type == = ".docx" || type == = ".doc" ) {
fileSuffix = type ;
}
jq解析window.location
console.log( window.location.href) // 当前URL;例子:https://baijiahao.baidu.com/s?id= 1625846473808878131& wfr= spider& for= pc
console.log( window.location.protocol) // 协议;例子:https:
console.log( window.location.hostname) // 域名;例子:baijiahao.baidu.com
console.log( window.location.origin) // 协议+域名;例子:https://baijiahao.baidu.com
console.log( window.location.search) // 请求参数;例子:?id= 1625846473808878131& wfr= spider& for= pc
jq解析URL参数
function getParameter( name) {
// 正则:[ 找寻'&' + 'url参数名字' = '值' + '&' ] ('&' 可以不存在)
let reg = new RegExp( "(^|&)" + name +"=([^&]*)(&|$)" ) ;
let r = window.location.search.substr( 1) .match( reg) ;
if( r != null) {
// 对参数值进行解码
return unescape( r[ 2] ) ;
}
return null;
}
// 调用方法,注意需要传入String类型的数据,输出结果为String类型
getParameter( 'id' ) ; // '123'
// 使用正则表达式来匹配全路径下的?后的参数,避免
const getUrlValue = function ( name) {
let href = location.href
return decodeURIComponent(( new RegExp( '[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)' ) .exec( href) || [ , "" ] ) [ 1] .replace( /\+/g, '%20' )) || null
}
getUrlValue( 'inApp' )
const getUrlParameter = function ( name) {
let reg = new RegExp ( '(^|&)' + name + '=([^&]*)(&|$)' )
let r = window. location. search. substr ( 1 ) . match ( reg)
if ( r != null ) {
return unescape ( r[ 2 ] )
}
return null
}
const getQueryString = function ( key) {
var after = window. location. search
if ( after. indexOf ( '?' ) === - 1 ) {
return ''
}
after = after. substr ( 1 ) || window. location. hash. split ( '?' ) [ 1 ]
if ( after) {
var reg = new RegExp ( '(^|&)' + key + '=([^&]*)(&|$)' )
var r = after. match ( reg)
if ( r != null ) {
return decodeURIComponent ( r[ 2 ] )
} else {
return ''
}
}
}
const getUrlValue = function ( name) {
let href = location. href
return decodeURIComponent ( ( new RegExp ( '[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)' ) . exec ( href) || [ '' , '' ] ) [ 1 ] . replace ( /\+/g , '%20' ) ) || null
}
const getUrlParse = function ( ) {
let url = window. location. search
let obj = { }
let reg = / [ ? & ] [ ^ ? & ] += [ ^ ? & ] + / g
let arr = url. match ( reg)
if ( arr) {
arr. forEach ( item => {
let tempArr = item. substring ( 1 ) . split ( '=' )
let key = decodeURIComponent ( tempArr[ 0 ] )
let val = decodeURIComponent ( tempArr[ 1 ] )
obj[ key] = val
} )
}
return obj
}
const getUrlParses = function ( ) {
let url = window. location. href. split ( '#' ) [ 1 ]
console. log ( window. location. href)
let querys = url. substring ( url. indexOf ( '?' ) + 1 ) . split ( '&' )
let result = { }
if ( url. indexOf ( '?' ) === - 1 ) {
return { }
}
for ( let i = 0 ; i < querys. length; i++ ) {
let temp = querys[ i] . split ( '=' )
if ( temp. length < 2 ) {
result = { }
} else {
result[ temp[ 0 ] ] = temp[ 1 ]
}
}
return result
}
export {
getUrlParameter,
getQueryString,
getUrlValue,
getUrlParse,
getUrlParses
}
获取url参数
getUrlValue ( name) {
let href = location. href
return (
decodeURIComponent (
( new RegExp ( '[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)' ) . exec ( href) || [ '' , '' ] ) [ 1 ] . replace (
/\+/g ,
'%20'
)
) || null
)
} ,
删除URL中的某个参数
delParamsQuery ( name) {
var loca = window. location;
var baseUrl = loca. origin + loca. pathname + loca. hash. substring ( 0 , loca. hash. indexOf ( '?' ) + 1 ) ;
var query = loca. hash. substring ( loca. hash. indexOf ( '?' ) + 1 ) ;
if ( query. indexOf ( name) > - 1 ) {
var obj = { }
var arr = query. split ( "&" ) ;
for ( var i = 0 ; i < arr. length; i++ ) {
arr[ i] = arr[ i] . split ( "=" ) ;
obj[ arr[ i] [ 0 ] ] = arr[ i] [ 1 ] ;
} ;
delete obj[ name] ;
var url = baseUrl + JSON . stringify ( obj) . replace ( /[\"\{\}]/g , "" ) . replace ( /\:/g , "=" ) . replace ( /\,/g , "&" ) ;
return url
} else {
return window. location. href;
} ;
} ,
判断是否在微信
isWX ( ) {
let wxInfo = navigator. userAgent. toLowerCase ( )
if ( wxInfo. match ( /MicroMessenger/i ) == 'micromessenger' ) {
window. localStorage. setItem ( 'isWX' , true )
return true
} else {
window. localStorage. setItem ( 'isWX' , false )
return false
}
}
数组拼接
let union = a. concat ( b)
修改修改对象中的数据
this . setData ( {
[ 'prizeList[' + 4 + '].prizePic' ] : 'url'
} )