发表于: 2017-06-05 14:50:24

1 1178


今天完成的事情:

1.今天修改了task1代码中不太简洁的部分,如下图所示,随机获取颜色的代码,为每一个颜色值都设置了随机数,虽然也可以实现功能,但是太不简洁,如果换成是大量的数据,这种办法就完全不可取

获取随机颜色(原来的笨方法)
var a = Math.floor(Math.random() * 255);
b = Math.floor(Math.random() * 255);
c = Math.floor(Math.random() * 255);
var d = Math.floor(Math.random() * 255);
e = Math.floor(Math.random() * 255);
f = Math.floor(Math.random() * 255);
var g = Math.floor(Math.random() * 255);
h = Math.floor(Math.random() * 255);
z = Math.floor(Math.random() * 255);

color[0] = "rgb("+a+","+b+","+c+")";
color[1] = "rgb("+e+","+f+","+d+")";
color[2] = "rgb("+g+","+h+","+z+")";

在师姐的建议下,用了十六进制颜色表示,这一小行代码就实现了同样的功能,不得不感叹算法的强大

var color = new Array(3);
for (var j = 0; j < color.length; j++) {
color[j] = '#' + Math.floor(Math.random() * 16777215).toString(16);

2.开始task2的内容,简单的理解了杀人游戏的逻辑,第一次接触这个游戏,幸好昨天师兄师姐们一起教我们玩了两局。学习了js方式的页面跳转;按钮式:(js点击跳转) <INPUT name="pclog" type="button" value="GO" onClick="location.href='http://www.jb51.net/'">;

3.学会了如何用JS获取表单标签中的内容;举个栗子:

<input type="text" name="name" class="txt-com-name" value="aaa" maxlength="100" id="input1" name="input1"/>

<script> var value = document.getElementById("input1").value;

 alert(value);

</script>

明天的计划:继续task2任务的学习,还有弄好那个SVN,感觉有点麻烦,当初学会用git上传管理代码也是花了很久

遇到的问题:暂无,JS的很多语法不会,基础需要打牢

收获:完成了task1的demo,学会了JS的页面跳转还有获取表单内容


返回列表 返回列表
评论

    分享到