varonCheckOneListsClick =(e)=> { if (e.target.tagName !== 'INPUT') { return; } var checkNumber = 0; for (let i = 0; i < checkOneLists.length; i++) { checkOneLists[i].checked && checkNumber++; } checkAll.checked = checkNumber === checkOneLists.length; }
这个是添加事件,指定触发对象,还有一个字符的比较
1 2 3 4 5 6 7 8 9 10 11 12 13 14
var handleThsClickFn = function (th, index) { if (index === 0) return; th.addEventListener('click', function () { var arr = Array.prototype.slice.call(rows).sort(function (a, b) { if (index === 2 || index === 4){ return a.getElementsByTagName('td')[index].innerHTML.localeCompare(b.getElementsByTagName('td')[index].innerHTML,'zh'); } return a.getElementsByTagName('td')[index].innerHTML - b.getElementsByTagName('td')[index].innerHTML; }) for (let i = 0; i < arr.length; i++) { tbody.appendChild(arr[i]); } }); }
4.三级联动效果
这个就是常规js动态生成元素
5.积分抽奖效果
更多是学习一种思路
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
var runGame = function () { var random = Math.floor(Math.random() * 6000 + 3000) timer = setInterval(function () { random -= 200 if (random < 200) { clearInterval(timer) timer = null openDialog() return } currentIndex = ++index % prizeList.length prizeList.forEach(function (node) { node.classList.remove('active') }) prizeList[currentIndex].classList.add('active') }, 50) }
条评论