201711671215
作业
1.通过js获取输入框中的vlaue值
2.点击某个元素,更改该元素的样式
3.互换变量值
4.乘法口诀
第一,二道题的实现
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script type="text/javascript"> window.οnlοad=function() { var test = document.getElementById("test"); alert("输入框中value的值:"+test.value); <!--js获取输入框中的vlaue值--> console.log(test.value); this.οnclick= function () { <!--点击某个元素,更改该元素的样式--> test.style.color = "red"; console.log(test); } test.οnblur=function(){ this.style.color="yellow"; } test.οnmοuseοver=function(){ test.style.color="orange"; } test.οnmοuseοut=function(){ this.style.color="pink"; } } </script> </head> <body> 测试专用框:<input type="text"id="test"value="Hello,world!"> </body> </html>
第三道题的实现
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script type="text/javascript"> var a=2; var b=8; document.write("a,b交换前的值"+a+" "+b); a=a^b; b=a^b; a=a^b; document.write("<br/>"); document.write("a,b交换后的值"+a+" "+b); </script> </head> <body> </body> </html>
第四道题的实现
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <script> document.write("<table border='1' style='color:red;'>"); for(var x = 1; x<=9;x++){ document.write("<tr>") for(var y = 1; y<=x; y++){ document.write("<td>"+x+"x"+y+"="+x*y+"</td>"); } for(var m= 1; m <=9-x; m++ ){ document.write("<td> </td>"); } document.write("</tr>"); } document.write("</table >"); </script> <title></title> </head> <body> </body> </html>