var gameListDom = document.getElementById('game_list'); // console.log(gameListDom);确保获取id对象不为空
//divDom.className = "productRow" 是css中定义好的样式id名 进行优化样式处理 for (var i = 0; i < GAME_LIST.length; i++) { var imageDom = document.createElement('img'); imageDom.src = GAME_LIST[i].logo; console.log('Link' + i + ':' + GAME_LIST[i].logo); var divDom = document.createElement('div'); divDom.className = "productRow" divDom.appendChild(imageDom); let dd = '' + GAME_LIST[i].url divDom.onclick = function(){ window.location = dd } gameListDom.appendChild(divDom); }
html跳转链接时传递参数
传递参数 a=1 window.location.href = new.html?a=1 接受参数
1 2 3 4 5 6 7 8 9 10 11 12 13
<script> // 获取url中的参数 function getUrlParam(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); var r = window.location.search.substr(1).match(reg); if (r != null) { return unescape(r[2]); } else { return null; } } let a = getUrlParam('a') </script>