diff --git a/js/main.js b/js/main.js index b72ce5e..9204617 100644 --- a/js/main.js +++ b/js/main.js @@ -7,6 +7,8 @@ if(storedata&&storedata.length>0){ storageSave(maindata) } + +// 默认展示十条数据 function storageSave(_data){ var _maindata=[]; @@ -21,26 +23,19 @@ function storageSave(_data){ creatElement(_maindata) } +// 根据本地存储的数据生成节点信息 function creatElement(_maindata){ var html = ''; for (var i = 0; i < _maindata.length; i++) { - - html += '
  • ' - if(_maindata[i].bgColor){ - html += ''; - }else{ - html += ''; - } - if(_maindata[i].ico){ - html += ''; - }else{ - html += _maindata[i].name[0]?_maindata[i].name[0]:""; - } - html += ''+_maindata[i].name+'
  • '; + + html += temp('
  • $_content$$_name$
  • ',{ + _URL:_maindata[i].url?_maindata[i].url:'', + _name:_maindata[i].name, + _bgColor:_maindata[i].bgColor?_maindata[i].bgColor:'#EAEAEA', + _content:_maindata[i].ico?'':(_maindata[i].name[0]?_maindata[i].name[0]:"") + }) }; $('#iconList').append(html); diff --git a/js/template.simple.js b/js/template.simple.js new file mode 100644 index 0000000..30cbf9c --- /dev/null +++ b/js/template.simple.js @@ -0,0 +1,6 @@ +window.temp = function(str,obj){ + return str.replace(/\$\w+\$/gi, function(matchs) { + var returns = obj[matchs.replace(/\$/g, "")]; + return typeof returns === "undefined" ? "" : returns; + }); +} \ No newline at end of file