<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>随便敲敲</title>
	</head>
	<body>
    	 <form action="" >
    	 	<lable>加数1</lable>
    	 	<input type="text" name="a" id="a" value="1"/>
    	 	<lable>加数1</lable>
    	 	<input type="text"  name="b" id="b" value="2"/>
    	 	<input type="submit" value="求和"  onclick="sum()" />
    	 </form>
	</body>
	<script type="text/javascript">
		function sum(){
			 
	    let a=document.getElementById('a');    /*document.querySelector("#a")*/
	  	let b=document.getElementById('b');
	  	let c;
	  	c=parseInt(a.value)+parseInt( b.value);
	  	window.alert(c);
		}
	</script>
</html>

html+js

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>随便敲敲</title>
	</head>
	<body>
    	 <form action="" >
    	 <lable>1+2+3+...+20=</lable>
    	  <br />
    	 <span id="a"></span>
    	 </form>
	</body>
	<script type="text/javascript">
	let sum=0;
	for(let i=1;i<=20;i++)
	{
		sum=sum+i;
	}
	console.log(sum);
	let h=document.querySelector("#a");
	h.innerHTML=sum;
	</script>
</html>

html+js

相关文章:

  • 2021-07-21
  • 2021-10-28
  • 2022-12-23
  • 2022-12-23
  • 2021-12-10
  • 2021-11-22
  • 2021-04-19
  • 2021-08-15
猜你喜欢
  • 2022-12-23
  • 2021-12-04
  • 2021-11-22
  • 2021-04-18
  • 2021-04-19
相关资源
相似解决方案