1背犯、cookie
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>cookie</title>
<style type="text/css">
</style>
<script type="text/javascript" src="js/jquery-1.12.4.min.js"></script>
<script type="text/javascript" src="js/jquery.cookie.js"></script>
<script type="text/javascript">
//cookie的讀和寫需要在服務器環(huán)境下
//寫cookie
//參數(shù):名稱坏瘩、值、有效期幾天漠魏、路徑
$.cookie('mycookie','ok!',{expires:7,path:'/'});
//讀cookie
var val = $.cookie('mycookie');
alert(val);//ok!
</script>
</head>
<body>
</body>
</html>
2倔矾、本地存儲
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>本地存儲</title>
<style type="text/css">
</style>
<script type="text/javascript" src="js/jquery-1.12.4.min.js"></script>
<script type="text/javascript">
//寫入
//[{"id":1,"num":2,....},{}..]
localStorage.setItem('mystorage','ok!');
//讀取
alert(localStorage.mystorage);//ok!
//寫入
// sessionStorage.setItem('name','tom');
//讀取
alert(sessionStorage.name);//tom//沒有彈undefined
localStorage.setItem('mystorage','{"goods":["1","2"]}');
</script>
</head>
<body>
</body>
</html>
3、jQueryUI
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>jQueryUI</title>
<style type="text/css">
.con{
width: 300px;
height: 300px;
border: 1px solid #000;
margin: 50px auto 0;
}
.box{
width: 50px;
height: 50px;
background-color: gold;
cursor: pointer;/*鼠標經(jīng)過時指針為手的形狀*/
}
</style>
<script type="text/javascript" src="js/jquery-1.12.4.min.js"></script>
<script type="text/javascript" src="js/jquery-ui.min.js"></script>
<script type="text/javascript">
$(function(){
//draggable()使盒子可以任意拖動
$('.box').draggable({
//約束元素在父級內(nèi)拖動
containment:'parent',
//限制在X軸方向上可以拖動
axis:'x',
//拖動時透明度變?yōu)?0%
opacity:0.6,
//可以返回拖動的參數(shù)
drag:function(ev,ui){
// console.log(ui);//json格式的對象柱锹,offset是絕對位置哪自,position是相對父級的位置
console.log(ui.position.left);//從左到右是1到250
}
});
})
</script>
</head>
<body>
<div class="con">
<div class="box"></div>
</div>
</body>
</html>
最后編輯于 :
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者