<div class='addimg'></div>
<script>
var i=0,div=document.getElementsByTagName("div")[0]
function addimg(){
var input=document.createElement("input")//创建input
input.setAttribute("type","file")//设置type属性
input.setAttribute("name","a"+(++i))//设置name属性
div.appendChild(input)//插入到div内
}
</script>
帮你改了一下,能跑起来了。嗯.......你这个有一些语法问题和拼写不仔细的地方,估计太着急,有些粗心了~<!DOCTYPE html>
<html>
<head>
<title>canvas</title>
<style>
*{
padding: 0
margin: 0
}
#container{
height: 80vh
width: 80vw
margin-top: 10vh
margin-left: 10vw
border: 1px solid #aaff66
}
</style>
</head>
<body>
<div id="container">
<canvas id="canvas"></canvas>
</div>
</body>
<script type="text/javascript">
window.onload = function() {
var ctx = document.getElementById('canvas').getContext('2d')
var circle = function(x, y, radius, fillCircle) {
ctx.beginPath()
ctx.arc(x, y, radius, 0, Math.PI * 2, false)
ctx.closePath()
ctx.fillStyle="green"
if (fillCircle) {
ctx.fill()
} else {
ctx.stroke()
}
}
var width=canvas.width = document.getElementById('container').offsetWidth
var height=canvas.height = document.getElementById('container').offsetHeight
var Ball=function(){
this.x=width/2
this.y=height/2
this.xSpeed = 5
this.ySpeed=0
}
Ball.prototype.move=function(){
this.x+=this.xSpeed
this.y+=this.ySpeed
if(this.x<0){
this.x=width
}else if(this.x>width){
this.x=0
}else if(this.y<0){
this.y=height
}else if(this.y>height){
this.y=0
}
}
Ball.prototype.draw=function(){
circle(this.x,this.y,10,true)
}
var ball= new Ball()
setInterval(function(){
ctx.clearRect(0,0,width,height)
ball.draw()
ball.move()
},30)
}
</script>
</html>
document.getElementById("标签id")//获取指定的id标签document.getElementByName("标签name属性")//获取指定的name的标签如果有多个标签的name只相同就获取所有的name相同的标签
document.getElementByTagName("div") //获取所有的div标签获取 的是一个集合