-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
104 lines (93 loc) · 3.3 KB
/
main.js
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
if(module.hot){
// module.hot.accept()
module.hot.accept('./src/components/autoComplete')
module.hot.accept('./studyOpen.html')
}
import {router} from './src/lib/spaRouter';
import {AutoComplete} from './src/components/autoComplete';
import {Tab} from './src/components/tabOption';
import {LcCascade} from './src/components/lcCascade';
import {llocation} from './src/lib/location';
import './src/assert/css/cssList.css';
import './studyOpen.html'
console.log(756674)
window.onload = function () {
//autocomplete输入框
var input = 'input.input-autoComplete';
var data = ["java", "javascript", "js", "php", "python", "c++"];
new AutoComplete(input,data);
//创建一个tabOption对象
var options = {
dom: 'div.div-tabList div',
content: 'div.div-tabContent div',
defaultSelected: 1,
event: 'click',
selected: 'selected',
callback: function(tabIndex){
alert(tabIndex + 'selected');
}
};
new Tab(options);
//创建一个lcCascade对象
// var llocation = llocation; 这样复制会出错,是?
var lcButton = document.getElementById('commit');
var selectDiv = document.querySelector('div.div-selectedLc');
var lcOptions = {
lcList: 'div.div-lcList',
data: llocation,
defaultLocation: ['广东省','深圳市','福田区']
};
var lcCas = new LcCascade(lcOptions);
lcButton.addEventListener('click',function(){
var lastLocation = lcCas.getLastLocation();
if(confirm("确认选择:" + lastLocation.join('')+"?")){
var i = document.createElement('i');
i.style.display = 'block';
var time = new Date();
i.innerText = time.toLocaleDateString() + '---' + lastLocation.join('');
selectDiv.appendChild(i);
}
});
var autoDiv = document.querySelector('div.div-autoComplete');
var tabDiv = document.querySelector('div.div-tabOption');
var lcCascadeDiv = document.querySelector('div.div-lcCascade');
// autoDiv.style.display = 'none';
// tabDiv.style.display = 'none';
// lcCascadeDiv.style.display = 'none';
var content = document.querySelector('body');
function changeBgColor(color){
content.style.backgroundColor = color;
}
var aBt = document.querySelector('ul');
aBt.addEventListener('click', function(e){
e.preventDefault();
var tar = e.target;
var pageIndex = tar.href.lastIndexOf('/');
var page = tar.href.slice(pageIndex);
router.go(page);
},false);
router.setOptions({
// mode: "hash"
});
router.route("/", function(){
autoDiv.style.display = 'none';
tabDiv.style.display = 'none';
lcCascadeDiv.style.display = 'none';
});
router.route('/autoComplete',function(){
autoDiv.style.display = 'block';
tabDiv.style.display = 'none';
lcCascadeDiv.style.display = 'none';
});
router.route('/tabOption',function(){
autoDiv.style.display = 'none';
tabDiv.style.display = 'block';
lcCascadeDiv.style.display = 'none';
});
router.route('/lcCascade',function(){
autoDiv.style.display = 'none';
tabDiv.style.display = 'none';
lcCascadeDiv.style.display = 'block';
});
router.init();
}