Skip to content

Commit

Permalink
js 生成HTML
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Apr 18, 2015
1 parent 9402f82 commit 5b22e6f
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 31 deletions.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
#升级浏览器
#升级浏览器



## 调用方法

```js
window.outdatedbrowser({
"firefox":{
"url":"http://baidu.com"
}

})
```
14 changes: 11 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<link rel="stylesheet" type="text/css" href="outdatedbrowser.css">
</head>
<body>
<div class="outdatedbrowser">
<!-- <div class="outdatedbrowser">
<h1>请更新浏览器</h1>
<span class="split"></span>
<a class="browser chrome" href="#">
Expand Down Expand Up @@ -36,9 +36,17 @@ <h2><i class="icon"></i>OPERA</h2>
<h4>在以下操作系统可用 </h4>
<p><span class="windows">Windows</span><span class="windows">Mac OS</span><span class="windows">Linux</span></p>
</a>
</div>
</div> -->
<script type="text/javascript">
// window.outdatedbrowser()
window.outdatedbrowser({
"firefox":{
"url":"http://baidu.com"
}

})

var a = new outdatedbrowser()
console.log(a.browser)
</script>
</body>
</html>
75 changes: 48 additions & 27 deletions outdatedbrowser.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,56 @@
(function(window,document) {
window.outdatedbrowser=function(){

window.outdatedbrowser=function(json){
this.container = document.createElement('div'),
this.container.className = 'outdatedbrowser'
this.browser = {
"firefox":{
"url":"http://www.mozilla.org/firefox/new/",
"available":["windows","mac","linux"],
"title":"Mozilla Firefox"
},
"internetExplorer":{
"url":"http://windows.microsoft.com/en-us/internet-explorer/download-ie",
"available":["windows"],
"title":"INTERNET EXPLORER"
},
"chrome":{
"url":"http://www.google.com/chrome",
"available":["windows","mac","linux"],
"title":"GOOGLE CHROME"
},
"safari":{
"url":"http://support.apple.com/downloads/#safari",
"available":["mac"],
"title":"APPLE SAFARI"
},
"safari":{
"url":"http://www.opera.com/download",
"available":["windows","mac","linux"],
"title":"OPERA"
}
"firefox":{
"url":"http://www.mozilla.org/firefox/new/",
"available":["windows","mac","linux"],
"title":"Mozilla Firefox"
},
"internetExplorer":{
"url":"http://windows.microsoft.com/en-us/internet-explorer/download-ie",
"available":["windows"],
"title":"INTERNET EXPLORER"
},
"chrome":{
"url":"http://www.google.com/chrome",
"available":["windows","mac","linux"],
"title":"GOOGLE CHROME"
},
"safari":{
"url":"http://support.apple.com/downloads/#safari",
"available":["mac"],
"title":"APPLE SAFARI"
},
"opera":{
"url":"http://www.opera.com/download",
"available":["windows","mac","linux"],
"title":"OPERA"
}
}

container.innerHTML = "content"
this.html = ''
this.html += '<span class="split"></span>'
for (var a in this.browser) {
this.html += temp('<a class="browser $class$" href="$url$"> <h2><i class="icon"></i>$title$</h2> <span class="btn">下载</span> <h4>在以下操作系统可用 </h4> <p>$available$</p> </a>',{
class:a,
title:this.browser[a].title,
available: '<span>' +this.browser[a].available.join('</span> <span>') + '</span>',
url:this.browser[a].url
})
};
container.innerHTML = this.html
document.body.appendChild(container)
}
function isVal (ty) {
// body...
}
function temp(str,obj){
return str.replace(/\$\w+\$/gi, function(matchs) {
var returns = obj[matchs.replace(/\$/g, "")];
return typeof returns === "undefined" ? "" : returns;
});
}
})(window,document)

0 comments on commit 5b22e6f

Please sign in to comment.