面试问题小结
找工作快一个月了,辞职也有半个月了,还是没定。这个星期在看《AngularJS权威教程》,是1.2.x版的,也没什么动力看。面试受虐,挣扎整理~(其实是一些很基础的问题,我现在水平很差,从这里可看出。我不会放弃的,js我今年一定要精通。)
1 三个函数
split():把字符串分割成字符串数组;
用法:String.split(sep,howmany);
例子:'hello'.split('');//'h','e','l','l','o'
备注:howmany参数表示返回的数组长度,省略表示全部返回
splice():向数组添加或删除几个元素
用法:Array.splice(index,howmany,additem);
例子:var arr = ['1','2','3'];
arr.splice(1,1,4);//2
document.write(arr);//1,4,3
备注:返回值是删除的元素;该方法会改变原始数组;index表示开始的位置,howmany表示删掉的数量,additem表示添加的项
slice():从已有数组中返回选择的元素
用法:Array.slice(start,end);
例子:var arr = ['1','2','3'];
arr.slice(1,2)//返回2
备注:start开始时的位置,end结束时的位置(不包括此位置的值);不改变原数组;
2如何去掉数组中重复的项
答:
<script type="text/javascript">
var student = ['1','1','2','3','4','2','2','6'];
function unique(arr){
// 遍历arr数组,把元素分别放入tmp数组(不存在才放)
var tmp = new Array();
for(var i in arr){
//该元素在tmp内部不存在才允许追加
if(tmp.indexOf(arr[i]) == -1){
tmp.push(arr[i]);
}
}
return tmp;
}
document.write(unique(student)+'<br>');
document.write(student);
</script>
3 求5!的值(用递归方法)
<script type="text/javascript">
var sum = function(item){
if(item <= 1){
return 1
}else{
return item * sum(item -1)
}
return sum;
}
alert(sum(5));
</script>
4 让一个div块在浏览器中居中
<head> <meta charset="UTF-8"> <title>Document</title> <style> body{ width:100%; height: 1300px; } .box{ width:300px; height:300px; background-color:pink; position: fixed;/*这里我用的是fixed*/ top:50%; left:50%; margin:-150px 0 0 -150px;/*这里的值根据div的宽高设置*/ } </style> </head> <body> <div class="box"></div> </body> </html>
5 HTML5的新特性
http://blog.csdn.net/gane_cheng/article/details/52819118
6 Jquery生成元素(当时竟然没答出来,感觉面试时候问答问题的语气不对,说话太冲了让面试官很不爽。)
<script>
// window.onload = function(){
// var h1 = document.createElement('h1');
// var txt = document.createTextNode('标签内的文字');
// h1.appendChild(txt);
// document.body.appendChild(h1);
// }
$(function () {
var $h1 = $("<h1 id='title' class='red'>DOM文档对象模型</h1>");
$("body").append($h1);
});
</script>
7 纯css让圆形旋转(百度经验里就有)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style> .box{ width:200px; height:200px; position: fixed; top:50%; left:50%; margin:-150px 0 0 -150px; border-radius: 50%; background: -webkit-linear-gradient(red,green,pink,blue); background:-linear-gradient(red,green,pink,blue); -webkit-animation:circle 4s infinite linear; animation:circle 4s infinite linear; } @-webkit-keyframes circle{ 0%{ transform:rotate(0deg); } 100%{ transform:rotate(360deg); } } </style> </head> <body> <div class="box"></div> </body> </html>

8 display 的属性值(没想到会有这么多)

9伪类和伪元素



2017-05-28
18:56:06

浙公网安备 33010602011771号