<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
input{
vertical-align: middle;
height: 30px;
padding: 0;
}
span{
display: inline-block;
width: 30px;
height: 30px;
border: 1px dashed yellowgreen;
vertical-align: middle;
font: 20px/30px "";
text-align: center;
}
p{
width: 200px;
height: 30px;
border: 2px solid orange;
vertical-align: middle;
display: inline-block;
background: #8df;
}
div{
display: inline-block;
width: 30px;
height: 30px;
font: 20px/30px "";
text-align: center;
border: 1px solid #000;
background: #ccc;
cursor: pointer;
}
</style>
</head>
<body>
<input type="text" placeholder="输入数字">
<span></span>
<input type="text" placeholder="输入数字">
<span style="cursor: pointer;">=</span>
<p></p>
<br>
<div>+</div>
<div>-</div>
<div>*</div>
<div>/</div>
<div>%</div>
<script>
var aInput = document.querySelectorAll('input');
console.log(aInput);
var aSpan = document.querySelectorAll('span');
console.log(aSpan);
var oP = document.querySelector('p');
console.log(oP);
var aDiv = document.querySelectorAll('div');
console.log(aDiv);
for(var i=0;i<aDiv.length;i++){
console.log(aDiv[i]);
aDiv[i].onclick = function(){
aSpan[0].innerHTML = this.innerHTML;
}
}
aSpan[1].onclick = function(){
var num1 = aInput[0].value;
console.log(num1);
var num2 = aInput[1].value;
console.log(num2);
var ysf = aSpan[0].innerHTML;
console.log(ysf);
if(num1==="" || num2===""){
alert('没有输入数字,请输入后计算')
}else if(ysf === ''){
alert('请选择运算符后计算')
}else if(ysf === '+'){
oP.innerHTML = +num1 + +num2;
}else if(ysf === '-'){
oP.innerHTML = num1 - num2;
}else if(ysf === '*'){
oP.innerHTML = num1 * num2;
}else if(ysf === '/'){
oP.innerHTML = num1 / num2;
}else if(ysf === '%'){
oP.innerHTML = num1 % num2;
}
aInput[0].value = '';
aInput[1].value = '';
aSpan[0].innerHTML = '';
}
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
#box{
width: 200px;
height: 200px;
background: yellow;
}
</style>
</head>
<body>
<div id="box"></div>
<script>
console.log(this);
function fn1(){
console.log(this);
}
fn1();
document.querySelector('#box').onclick = function(){
console.log(this);
}
setInterval(function(){
console.log(this);
},3000);
var obj = {
name: 'haha',
age: 18,
hello: function(){
console.log(this);
console.log(this.age);
}
}
obj.hello();
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
#box{
height: 30px;
border: 5px groove orange;
border-radius: 20px;
position: relative;
}
#box p{
margin: 0;
width: 0;
height: 30px;
background: pink;
border-radius: 15px;
}
#box span{
width: 100px;
height: 30px;
background: rgba(0,0,0,.3);
text-align: center;
font: 20px/30px "楷体";
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
margin: auto;
}
</style>
</head>
<body>
<div id="box" style="width: 800px;">
<p></p>
<span>0%</span>
</div>
<script src="./../../../public.js"></script>
<script>
var oBox = document.querySelector('#box');
console.log(oBox);
var oChild = document.querySelector('#box>p');
console.log(oChild);
var oBili = document.querySelector('#box>span');
console.log(oBili);
var oBoxWidth = +oBox.style.width.slice(0,-2);
console.log(oBoxWidth);
var num = 0;
var timer = setInterval(function(){
num += randomNum(1,5);
oChild.style.width = num+'px';
oBili.innerHTML = (num/oBoxWidth*100).toFixed(2) + '%';
if(num>=oBoxWidth){
clearInterval(timer);
num = oBoxWidth;
oChild.style.width = num+'px';
oBili.innerHTML = num/oBoxWidth*100 + '%';
}
},50)
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
#box{
height: 30px;
border: 5px groove orange;
border-radius: 20px;
position: relative;
}
#box p{
margin: 0;
width: 0;
height: 30px;
background: pink;
border-radius: 15px;
}
#box span{
width: 100px;
height: 30px;
background: rgba(0,0,0,.3);
text-align: center;
font: 20px/30px "楷体";
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
margin: auto;
}
</style>
</head>
<body>
<div id="box" style="width: 800px;">
<p></p>
<span>0%</span>
</div>
<button id="start">开始</button>
<script src="./../../../public.js"></script>
<script>
var oBox = document.querySelector('#box');
console.log(oBox);
var oChild = document.querySelector('#box>p');
console.log(oChild);
var oBili = document.querySelector('#box>span');
console.log(oBili);
var oStart = document.querySelector('#start');
console.log(oStart);
var oBoxWidth = +oBox.style.width.slice(0,-2);
console.log(oBoxWidth);
var num = 0;
var timer = null;
oStart.onclick = function(){
clearInterval(timer);
timer = setInterval(function(){
num += randomNum(1,5);
oChild.style.width = num+'px';
oBili.innerHTML = (num/oBoxWidth*100).toFixed(2) + '%';
if(num>=oBoxWidth){
clearInterval(timer);
num = oBoxWidth;
oChild.style.width = num+'px';
oBili.innerHTML = num/oBoxWidth*100 + '%';
}
},50)
}
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
#box{
height: 30px;
border: 5px groove orange;
border-radius: 20px;
position: relative;
}
#box p{
margin: 0;
width: 0;
height: 30px;
background: pink;
border-radius: 15px;
}
#box span{
width: 100px;
height: 30px;
background: rgba(0,0,0,.3);
text-align: center;
font: 20px/30px "楷体";
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
margin: auto;
}
</style>
</head>
<body>
<div id="box" style="width: 800px;">
<p></p>
<span>0%</span>
</div>
<button id="start">开始</button>
<button id="stop">暂停</button>
<script src="./../../../public.js"></script>
<script>
var oBox = document.querySelector('#box');
console.log(oBox);
var oChild = document.querySelector('#box>p');
console.log(oChild);
var oBili = document.querySelector('#box>span');
console.log(oBili);
var oStart = document.querySelector('#start');
console.log(oStart);
var oStop = document.querySelector('#stop');
console.log(oStop);
var oBoxWidth = +oBox.style.width.slice(0,-2);
console.log(oBoxWidth);
var num = 0;
var timer = null;
oStop.disabled = true;
oStart.onclick = function(){
clearInterval(timer);
oStop.disabled = false;
this.disabled = true;
timer = setInterval(function(){
num += randomNum(1,5);
oChild.style.width = num+'px';
oBili.innerHTML = (num/oBoxWidth*100).toFixed(2) + '%';
if(num>=oBoxWidth){
clearInterval(timer);
num = oBoxWidth;
oChild.style.width = num+'px';
oBili.innerHTML = num/oBoxWidth*100 + '%';
oStop.disabled = true;
}
},50)
}
oStop.onclick = function(){
clearInterval(timer);
this.disabled = true;
oStart.disabled = false;
}
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
#box{
height: 30px;
border: 5px groove orange;
border-radius: 20px;
position: relative;
}
#box p{
margin: 0;
width: 0;
height: 30px;
background: pink;
border-radius: 15px;
}
#box span{
width: 100px;
height: 30px;
background: rgba(0,0,0,.3);
text-align: center;
font: 20px/30px "楷体";
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
margin: auto;
}
</style>
</head>
<body>
<div id="box" style="width: 800px;">
<p></p>
<span>0%</span>
</div>
<button id="start">开始</button>
<button id="stop">暂停</button>
<button id="reset">重置</button>
<script src="./../../../public.js"></script>
<script>
var oBox = document.querySelector('#box');
console.log(oBox);
var oChild = document.querySelector('#box>p');
console.log(oChild);
var oBili = document.querySelector('#box>span');
console.log(oBili);
var oStart = document.querySelector('#start');
console.log(oStart);
var oStop = document.querySelector('#stop');
console.log(oStop);
var oReset = document.querySelector('#reset');
console.log(oReset);
var oBoxWidth = +oBox.style.width.slice(0,-2);
console.log(oBoxWidth);
var num = 0;
var timer = null;
oStop.disabled = true;
oReset.disabled = true;
oStart.onclick = function(){
clearInterval(timer);
oStop.disabled = false;
oReset.disabled = false;
this.disabled = true;
timer = setInterval(function(){
num += randomNum(1,5);
oChild.style.width = num+'px';
oBili.innerHTML = (num/oBoxWidth*100).toFixed(2) + '%';
if(num>=oBoxWidth){
clearInterval(timer);
num = oBoxWidth;
oChild.style.width = num+'px';
oBili.innerHTML = num/oBoxWidth*100 + '%';
oStop.disabled = true;
}
},50)
}
oStop.onclick = function(){
clearInterval(timer);
this.disabled = true;
oStart.disabled = false;
}
oReset.onclick = function(){
this.disabled = true;
oStop.disabled = true;
oStart.disabled = false;
clearInterval(timer);
num = 0;
oChild.style.width = '0px';
oBili.innerHTML = '0%';
}
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.box{
width: 400px;
border: 10px double pink;
background: orange;
}
</style>
</head>
<body>
<div class="box">
hello world!!!
<p>pbox</p>
<em>hahah</em>
<span>lala</span>
<nav>navbox</nav>
</div>
<header style="height: 50px;background: yellow">header</header>
<script>
var obox = document.querySelector('.box');
console.log(obox);
var oem = document.querySelector('.box em');
console.log(oem);
var ospan = document.querySelector('.box span');
console.log(ospan);
var onav = document.querySelector('.box nav');
console.log(onav);
console.log('-----------------华丽的分割线--------------');
var oh3 = document.createElement('h3')
console.log(oh3);
oh3.innerHTML = '这是一个h3标签'
var ostrong = document.createElement('strong');
console.log(ostrong);
ostrong.innerHTML = '这是一个strong标签'
var ofooter = document.createElement('footer');
console.log(ofooter);
ofooter.innerHTML = '这是一个footer标签'
console.log('-----------------华丽的分割线--------------');
obox.appendChild(oh3);
obox.insertBefore(ostrong,oem);
console.log('-----------------华丽的分割线--------------');
obox.removeChild(ospan);
console.log('-----------------华丽的分割线--------------');
let o1 = obox.cloneNode();
console.log(o1);
let o2 = obox.cloneNode(true);
console.log(o2);
document.body.appendChild(o1);
document.body.appendChild(o2);
obox.replaceChild(ofooter,onav);
</script>
</body>
</html>