```
function Li(options) {
function TabLiContent(options) {
this._init(options);
}
TabLiContent.prototype = {
// 數據初始化
_init : function(options) {
this.tabIndex = options.tabIndex || 0;
this.liNum = options.liNum || 0;
this.container = options.container || null;
this.index = options.index || 0;
return this;
},
// 數據校驗
_checkData : function() {
if (this.container == null) {
throw new Error('have not container');
}
return this;
},
// 隨機填充container
_makeLi : function() {
this._checkData();
var str = '';
str += '<li data-index='+this.index+' data-tab='+this.tabIndex+' class="li_con">'
str += '<span data-index='+this.index+' data-tab='+this.tabIndex+' class="li_word">這是第' + this.tabIndex + 'tab欄的第' + this.liNum + '個li</span>'
str += '<span class="list_ok" data-index='+this.index+' data-tab='+this.tabIndex+'>刪除</span>'
str += '</li>';
return str;
},
// 獲取當前對象的數據
_getObjSData:function(dom){
return dom.dataset;
},
// 點擊跳轉詳情
_openDetail: function(data) {
var that = this;
var data = that._getObjSData(data);
console.log(data);
alert('即將打開' +data.index+'商品詳情的頁面 '+data.tab+'');
},
// 刪除
_delListOne:function(data) {
var that = this;
var data = that._getObjSData(data);
console.log(data);
alert('即將刪除此商品' +data.index+'')
},
// 事件綁定[所有的點擊事件通過事件委托方式綁定]
_bindEvent : function(options) {
var con = this.container;
var that = this;
con.onclick = function(ev) {
var ev = ev || window.event;
var target = ev.target || ev.srcElement;
switch(target.className){
case 'li_con':
// 進入詳情
that._openDetail(target);
break;
case 'list_ok':
// 刪除
that._delListOne(target);
break;
case 'li_word':
// 進入詳情
that._openDetail(target);
break;
}
}
},
main : function() {
try {
this._checkData();
this.container.innerHTML += this._makeLi();
} catch(e) {
console.log(e);
}
}
}
return function(options) {
var tabLiContent = new TabLiContent(options);
tabLiContent.main();
tabLiContent._bindEvent(options);
return tabLiContent;
}(options);
}
```
```
var dom = document.querySelector('#listOne');
var dom1 = document.querySelector('#listTwo');
var dom2 = document.querySelector('#listThree')
var json = [{
tabIndex : 0,
liNum : 1,
container : dom,
index : 0
}, {
tabIndex : 0,
liNum : 2,
container : dom,
index : 1
}, {
tabIndex : 0,
liNum : 3,
container : dom,
index : 2
}, {
tabIndex : 0,
liNum : 4,
container : dom,
index : 3
}];
var json1 = [{
tabIndex : 1,
liNum : 1,
container : dom1,
index : 0
},
{
tabIndex : 1,
liNum : 2,
container : dom1,
index : 1
},
{
tabIndex : 1,
liNum : 3,
container : dom1,
index : 2
}];
var json2 = [{
tabIndex : 2,
liNum : 1,
container : dom2,
index : 0
},
{
tabIndex : 2,
liNum : 2,
container : dom2,
index : 1
},
{
tabIndex : 2,
liNum : 3,
container : dom2,
index : 2
}];
json.forEach(function(item) {
Li(item);
})
json1.forEach(function(item) {
Li(item);
})
json2.forEach(function(item){
Li(item);
})
```
- css用法技巧
- 陰影被后面div遮擋
- 繪制一個三角形
- 圖像的灰白處理
- 一切居中
- 禁用鼠標事件
- 模糊文本
- 字體省略號
- 垂直居中
- box投影
- css動畫
- javaScript常見工具封裝
- 地址欄參數獲取
- 日期格式化
- Ajax
- scroll
- 緩動函數
- 事件綁定
- 阻止冒泡和默認行為
- 偽數組正常化
- 日期生成
- 拷貝
- javaScript基本知識
- javaScript基本知識
- javascript常見代碼塊
- vue常見問題
- 獲取參數
- vue常見問題/vue混入
- v-html指令問題集錦
- 正則獲取html中所有的中文字符
- 時間格式化
- 監聽路由的變化
- vue移動端滑動事件
- vue移動端圖片點擊放大
- 打包后背景圖片404的問題
- webpack打包后部分樣式失效
- IE的兼容問題
- post請求后臺無法接受參數
- 驗證碼
- vue開啟Gzip報錯
- v-html修改樣式
- app.css文件過大
- vue中中使用iframe
- babel對es6編譯不徹底 出現ie不兼容的問題
- vue單頁應用優化
- 吸頂問題
- 跨域session無法共享
- 登陸返回上一頁
- axois中使用delete數據傳遞問題
- 監聽數組對象數組中的屬性
- webpack
- webpack基本使用
- webpack打包刪除注釋
- js插件
- 輪播圖
- 面向對象模板
- 左滑右滑
- 存儲
- appcan
- appcan
- js深入研究
- 數組的參數傳遞問題
- 采用jquery的方法載入公共頁面后出現閃爍的問題
- html拼接無法綁定事件
- 吸頂問題
- async配合promise使用
- flutter
- 模擬器加載報錯
- 底部導航實現
- 模擬器出現錯誤
- flutter在idea下的快捷鍵
- flutter學習筆記
- 設計模式
- 觀察者模式
- nest
- nest基本說明
- nest錯誤處理
- vue高級
- 動態注入路由
- nest實戰
- 一項目準備
- window
- 端口進程被占
- mis包
- reactNative
- react-native-router-flux
- esLint
- eslint
- Cesium