url传参中文乱码
encodeURI ( encodeURI ( dat) )
decodeURI ( decodeURI ( dat) )
获取url拼接参数
function getUrlParam ( name ) {
var reg = new RegExp ( "(^|&)" + name + "=([^&]*)(&|$)" ) ;
var r = window. location. search. substr ( 1 ) . match ( reg) ;
if ( r != null ) return unescape ( r[ 2 ] ) ;
return null ;
}
ajax请求
$. ajax ( {
url: "/tes/add" ,
type: "post" ,
contentType: "application/x-www-form-urlencoded" ,
data: {
params: val
} ,
dataType: 'json' ,
success : function ( res ) {
} ,
error : function ( ) {
layer. msg ( '请求服务器失败!!' )
}
} ) ;
返回上一页
window. history. go ( - 1 ) ;
window. history. back ( ) ;
刷新界面
location. reload ( ) ;
缓存使用
localStorage. setItem ( key, value) ;
localStorage. getItem ( key) ;
延时处理
setTimeout ( function ( ) {
} , 1000 )
delay教程连接
定时器
var interval= setInterval ( function ( ) {
console. log ( 1 )
} , 1000 )
window. clearInterval ( interval) ;
var interval= setInterval ( function ( ) {
console. log ( 1 )
} , 1000 )
setTimeout ( function ( ) {
window. clearInterval ( interval) ;
} , 10000 )
获取/设置 标签属性
$ ( "#img" ) . attr ( "src" , "www.baidu.com" ) ;
$ ( "#img" ) . attr ( "src" ) ;
.val .text .html
< div id= "tes" >
< div> 22 < span> 1 < / span> < / div>
< / div>
console. log ( $ ( '#tes' ) . html ( ) ) ;
console. log ( $ ( '#tes' ) . text ( ) ) ;
< div id= "tes" > < / div>
$ ( '#tes' ) . html ( '<div> 22 <span>1</span> </div>' )
$ ( '#tes' ) . text ( '<div> 22 <span>1</span> </div>' )
input标签
disabled= "disabled"
style= "border: none;"
autocomplete= off
select标签
$ ( "#sele option:checked" ) . text ( )
$ ( '#sele' ) . val ( )
js实现点击按钮复制
< ! DOCTYPE html>
< html>
< head>
< meta charset= "utf-8" >
< title> < / title>
< / head>
< body>
< div id= "text" > 我是被复制的内容< / div>
< button onclick= "copy()" > 复制< / button>
< input >
< / body>
< / html>
< script>
function copy ( ) {
var text = document. getElementById ( "text" ) . innerText;
var inp = document. createElement ( "input" ) ;
inp. value = text;
document. body. appendChild ( inp) ;
inp. select ( ) ;
document. execCommand ( "Copy" ) ;
document. body. removeChild ( inp) ;
}
< / script>