forked from wteam-xq/testDemo
-
Notifications
You must be signed in to change notification settings - Fork 1
/
utilsTest.html
111 lines (107 loc) · 4.27 KB
/
utilsTest.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<!DOCTYPE html>
<html>
<head>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-COMPATIBLE" content="IE=edge,chrome=1"/>
<meta charset="utf-8">
<title>
测试工具类页面
</title>
<link rel="icon" href="favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
<style>
.dragg_div{ width:200px; height:200px; background-color:#222; color:#fff; font-size:14px; text-align: center; cursor:move; }
.dragg_txt{ height: 200px; display: table-cell; vertical-align: middle; text-align: center; width:200px; }
</style>
</head>
<body>
<h3>测试工具类页面</h3>
<!-- 本部分代码来自: webStorage.html -->
<p>
1.localStorage 不清除缓存一直存在;
<input type="button" value="点击存入缓存" id="lSetBtn"/>
<input type="button" value="点击删除缓存" id="lRemoveBtn" />
<input type="button" value="点击查看缓存" id="lShowBtn" />
</p>
<p>
<span id="lBtnTips"></span>
</p>
<br/>
<div class="dragg_div" id="dragg_div">
<div class="dragg_txt">
<div>可拖动的方块</div>
<div>bug:input 无法编辑</div>
</div>
<input type="text" value="" class="dragg_input"/>
</div>
<!--[if lt IE 8]>
<script type="text/javascript" src="lib/json2.js"></script>
<![endif]-->
<script type="text/javascript" src="utils/base.js"></script>
<script type="text/javascript" src="lib/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="utils/client.js"></script>
<script type="text/javascript" src="utils/draggable.js"></script>
<script type="text/javascript" src="utils/localStorageUtil.js"></script>
<script>
var TestUtils = {
init: function(){
var This = this;
// this.insertScript();
// initlocalStorageDemo();
// 测试移动库
new Draggable({"wrapper": $("#dragg_div"), "boundary": "window"});
},
insertScript: function(){
var COOKIE_URL = 'utils/cookieUtil.js';
// 动态插入 cookie库脚本,并存储cookie
insertScript(COOKIE_URL, function(js){
CookieUtil.set('utilsTestCookie', 'xq, xq, sb');
});
}
};
TestUtils.init();
function initlocalStorageDemo(){
var localStorage, lSetBtn, lRemoveBtn, lShowBtn, lBtnTips;
lSetBtn = document.getElementById('lSetBtn');
lRemoveBtn = document.getElementById('lRemoveBtn');
lShowBtn = document.getElementById('lShowBtn');
lBtnTips = document.getElementById('lBtnTips');
localStorage = window.localStorage;
lSetBtn.onclick = localSetItem;
lRemoveBtn.onclick = localRemoveItem;
lShowBtn.onclick = showLocalStorage;
// 插入缓存
function localSetItem(event){
if (window.localStorage) {
localStorage.setItem('utilsTest', 'localStorageUtil');
lBtnTips.innerHTML = '保存成功!';
}else {
lBtnTips.innerHTML = '保存失败!';
}
}
// 显示storage, 转成字符串显示,JSON对象赋值之,ie8(不包括IE8)以下浏览器需引入json3
function showLocalStorage(){
if (window.localStorage) {
// IE7 IE6 特殊处理
if (client.browser.ie && parseInt(client.browser.ver,10) == 6 ) {
lBtnTips.innerHTML = 'utilsTest: ' + localStorage.getItem("utilsTest");
} else {
lBtnTips.innerHTML = 'localStorage: utilsTest:' + JSON.stringify(localStorage);
}
} else {
lBtnTips.innerHTML = '浏览器不支持localStorage';
}
}
// 清除缓存
function localRemoveItem(event){
if (window.localStorage) {
localStorage.removeItem('utilsTest');
lBtnTips.innerHTML = '删除成功!';
}else {
lBtnTips.innerHTML = '删除失败!';
}
}
}
</script>
</body>
</html>