functioncountDown(time){var nowTime =+newDate();var inputTime =+newDate(time);var times =(inputTime - nowTime)/1000;var d =parseInt(times /60/60/24);
d = d <10?'0'+ d : d;var h =parseInt(times /60/60%24);
h = h <10?'0'+ h : h;var m =parseInt(times /60%60);
m = m <10?'0'+ m : m;var s =parseInt(times %60);
s = s <10?'0'+ s : s;return d +'天'+ h +'时'+ m +'分'+ s +'秒';}
console.log(countDown('2023-3-19 21:00:00'));var date =newDate();
console.log(date
);
//先准备好数据var datas =[{name:'小王',subject:'JavaScript',score:100,scor:100},{name:'小张',subject:'JavaScript',score:98,scor:100},{name:'小赵',subject:'JavaScript',score:99,scor:100}];//往tbody里创建行var tbody = document.querySelector('tbody');for(var i =0; i < datas.length; i++){var tr = document.createElement('tr');
tbody.appendChild(tr);//行里面创建单元格for(var k in datas[i]){//创建单元格var td = document.createElement('td');
td.innerHTML = datas[i][k];
tr.appendChild(td);}//创建有删除的单元格var td = document.createElement('td');
td.innerHTML ='<a href="javascript:;">删除</a>';
tr.appendChild(td);}varas= document.querySelectorAll('a');for(var i =0; i <as.length; i++){as[i].onclick=function(){
tbody.removeChild(this.parentNode.parentNode);}}
发布留言
<style>
li a {float: right;}</style></head><body><textarea name="" id="">123</textarea><button>发布</button><ul><li>123</li></ul><script>//获取元素var btn = document.querySelector('button');var text = document.querySelector('textarea');var ul = document.querySelector('ul');//注册事件
btn.onclick=function(){//创建元素if(text.value ==''){alert('您没有输入内容');returnfalse;}else{var li = document.createElement('li');//添加元素
li.innerHTML = text.value +"<a href='javascript:'>删除</a>";
ul.insertBefore(li, ul.children[0]);//删除元素varas= document.querySelectorAll('a');for(var i =0; i <as.length; i++){as[i].onclick=function(){
ul.removeChild(this.parentNode);}}}}