淘宝Web前端开发常见面试题及答案整理

新华三前端开发面试|web前端开发编程软件h|html5前端开发面试题及答案

如有侵权请告明删除
题目1:JavaScript方面小贤是一条可爱的小狗(Dog),它的叫声很好听(wow),每次看到主人的时候就会乖乖叫一声(yelp)。从这段描述可以得到以下对象:
function Dog() {
this.wow = function() {
alert(’Wow’);
}
this.yelp = function() {
this.wow();
}
}
小芒和小贤一样,原来也是一条可爱的小狗,可是突然有一天疯了(MadDog),一看到人就会每隔半秒叫一声(wow)地不停叫唤(yelp)。请根据描述,按示例的形式用代码来实现(提示关键字: 继承,原型,setInterval)。
代码片段 1

<!DOCTYPE html>
<head>
    <meta charset=”utf-8″ />
    <title>哪些公司需要前端开发工具</title>
    <style type=”text/css”>
    </style>
</head>
<body>
    <input type=”button” value=”小贤” onclick=”xiaoxian.yelp();”>
    <input type=”button” value=”小芒” onclick=”xiaomang.yelp();”>
    <script>
        function Dog() {
            this.wow = function () {
                alert(‘Wow’);
            };
            this.yelp = function () {
                this.wow();
            };
        }
        function MadDog() {
            this.yelp = function () {
                var self = this;
                setInterval(self.wow, 500); //此处较原文由简化
            }
        }
        MadDog.prototype = new Dog();
        var xiaoxian = new Dog();
        var xiaomang = new MadDog();
    </script>
</body>
</html>

淘宝招聘官评语:
以上是较为规范的一个解法,我们希望通过此题,检查应聘者对js的语言基础及的面向对象开发的理解程度。其中的难点在于闭包的应用。

题目2:css方面使用纯css实现未知尺寸的图片(但高宽都小于200px)在200px的正方形容器中水平和垂直居中。

原文方法:
代码片段 2

<!DOCTYPE html public “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
    <meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
    <meta name=”Keywords” content=”简单的XHTML页面” />
    <meta name=”Description” content=”这是一个简单的XHTML页面” />
    <title>简单的XHTML页面</title>
</head>
<body>
    <style type=”text/css”>
        .box {
            display: table-cell;
            vertical-align: middle;
            width: 200px;
            height: 200px;
            text-align: center;
            /* hack for ie */
            *display: block;
            *font-size: 175px;
            /* end */
            border: 5px solid red;
        }
        .box img {
            vertical-align: middle;
        }
    </style>
    <div class=”box”>
        <img src=”http://www.w3cfuns.com/uc_server/avatar.php?uid=5463535&size=middle” alt=”” />
    </div>
</body>
</html>

淘宝招聘官评语:
很遗憾,这个解法用到了css hack。我们也不理解为什么设置font-size可以让IE显示垂直居中的效果。根据我们的计算,高度/字体大小的比值为1.14左右时IE可实现垂直居中。
当然还有很多其他的实现方案,但需要引入额外的标签。对于流量超大的淘宝网而言,我们经过权衡,倾向于在此问题上合理的使用hack。
其他方法:
代码片段 3

<!DOCTYPE html public “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
    <meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
    <meta name=”Keywords” content=”简单的XHTML页面” />
    <meta name=”Description” content=”这是一个简单的XHTML页面” />
    <title>简单的XHTML页面</title>
</head>
<body>
    <style type=”text/css”>
        .box {
            position: relative;
            width: 200px;
            height: 200px;
            /* hack for ie */
            *display: block;
            *font-size: 175px;
            /* end */
            border: 5px solid red;
        }
        .box img {
            display: block;
            position: absolute;
            top: 0;
            bottom: 0;
            right: 0;
            left: 0;
            margin: auto;
        }
    </style>
    <div class=”box”>
        <img src=”http://www.w3cfuns.com/uc_server/avatar.php?uid=5463535&size=middle” alt=”” />
    </div>
</body>
</html>

代码片段 4

<!DOCTYPE html public “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
    <meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
    <meta name=”Keywords” content=”简单的XHTML页面” />
    <meta name=”Description” content=”这是一个简单的XHTML页面” />
    <title>简单的XHTML页面</title>
</head>
<body>
    <style type=”text/css”>
        .box {
            position: relative;
            width: 200px;
            height: 200px;
            display: -webkit-box;
            -webkit-box-orient: horizontal;
            -webkit-box-pack: center;
            -webkit-box-align: center;
            /* hack for ie */
            *display: block;
            *font-size: 175px;
            /* end */
            border: 5px solid red;
        }
        .box img {}
    </style>
    <div class=”box”>
        <img src=”http://www.w3cfuns.com/uc_server/avatar.php?uid=5463535&size=middle” alt=”” />
    </div>
</body>
</html>

代码片段 5

<!DOCTYPE html>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
    <meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
    <meta name=”Keywords” content=”简单的XHTML页面” />
    <meta name=”Description” content=”这是一个简单的XHTML页面” />
    <title>简单的XHTML页面</title>
</head>
<body>
    <style type=”text/css”>
        .box {
            position: relative;
            width: 200px;
            height: 200px;
            line-height: 200px;
            text-align: center;
            /* hack for ie */
            *display: block;
            *font-size: 175px;
            /* end */
            border: 5px solid red;
        }
        .box img {
            vertical-align: middle;
        }
    </style>
    <div class=”box”>
        <img src=”http://www.w3cfuns.com/uc_server/avatar.php?uid=5463535&size=middle” alt=”” />
    </div>
</body>
</html>

题目3:XHMTL方面在不使用 border 样式的情况下,画出一条一px高的横线,在不同浏览器的Quirksmode和CSSCompat模式下都保持同一效果。

参考答案:
代码片段 6

<!DOCTYPE html public “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
    <meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
    <meta name=”Keywords” content=”简单的XHTML页面” />
    <meta name=”Description” content=”这是一个简单的XHTML页面” />
    <title>简单的XHTML页面</title>
</head>
<body>
    <div style=”height:1px;overflow:hidden;background:#000″></div>
</body>
</html>

复制代码
淘宝招聘官评语:
此题要点是要求在浏览器的 QuirksMode 和 CSSCompat 模式下效果一致。解法有很多,以上是我们认为的最为合理的一种。

题目4:JavaScript方面请给Array本地对象增加一个原型方法,它的用途是删除数组条目中重复的条目(可能有多个),返回值是一个包含被删除的重复条目的新数组。

参考答案:
[code]Array.prototype.distinct = function() {
var ret = [];
for (var i = 0; i < this.length; i++) {
for (var j = i+1; j < this.length;) {
if (this[i] === this[j]) {
ret.push(this.splice(j, 1)[0]);
} else {
j++;
}
}
}
return ret;
}
//for test
alert([‘a’,’b’,’c’,’d’,’b’,’a’,’e’].distinct());[/code]
复制代码
淘宝招聘官评语:
这是最为普通的解法。在数组元素数量不高的情况下,它的性能是可以接受的。相信一定有不少朋友有更好的解法,请告诉我们。

其他方法:
代码片段 7

<!DOCTYPE html public “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
    <meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
    <title>删除数组重复项</title>
    <style type=”text/css”>
    </style>
</head>
<body>
    <script>
        Array.prototype.distinct = function () {
            var newAry = [];
            this.forEach(function (item, index, array) {
                if (!newAry.some(function (itm, indx, ary) { if (itm === item) return true; })) {
                    newAry.push(item);
                }
            });
            return newAry;
        }
        oneAry = [12, 3, 4, 5, 7, 9, 0, 4, 45, 5, 675, 12, 45, 56, 45, 0];
        // a={b:1,c:2};
        // oneAry=[a,2,4,a];
        anotherAry = oneAry.distinct();
        document.write(oneAry + “</br>”);
        document.write(anotherAry);
    </script>
</body>
</html>

大疆面试前端开发|前端开发需要的代码编辑器|前端开发项目实战视频百度云

赞(0)
前端开发者 » 淘宝Web前端开发常见面试题及答案整理
64K

评论 抢沙发

评论前必须登录!