---
title: "js简单的面试题(2)"
author: "xiaomiya"
date: "2015-04-23T15:53:45Z"
tags: []
categories: ["Web前端"]
slug: "js-2"
draft: true
lastmod: "2015-04-24T15:30:16Z"
id: 2205495
url: "https://xiaomiya.iteye.com/blog/2205495"
---

续上一篇的js面试题

10，在ie6.0下面是不支持position：fixed的，请写一个js使用&lt;div id ="box"&gt;&lt;/div&gt;固定在页面的右下角

```
//如果用css实现的话
html{_background-image:url(about:blank);_background-attachment:fixed;}//这个是防止抖动的。
#time{ height: 2000px}
	.fixed-right{position:fixed;right:0px;left:auto;top:auto;bottom:0px;_position:absolute;_bottom:auto;_top:expression(eval(document.documentElement.scrollTop+document.documentElement.clientHeight-this.offsetHeight-(parseInt(this.currentStyle.marginTop,10)||0)-(parseInt(this.currentStyle.marginBottom,10)||0)));}
```

 

```
//2，使用js实现的话
window.onscroll= window.onresize = window.onload = function (){
var getDiv = document.getElementById('rightBottom');
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;

getDiv.style.left= document.documentElement.clientWidth - getDiv.offsetWidth+'px';
getDiv.style.top = document.documentElement.clientHeight-getDiv.offsetHeight +scrollTop +'px';
}


</script>
<div id="rightBottom" style=" width:100px; height:100px; background:blue; position:absolute; ">nihao</div>
```

 

 

11,js的基础对象有哪些，window和document的常用的方法和属性列出来

js的基础对象有：Array，Boolean，Date，Math，Number，String，ReqExp,Geqbal

 

window常用的属性有：

```
 defauleStatus：指定窗口状态栏中的信息。 
 status：指定当前窗口状态栏中的信息。 
 frames：是一个数组，其中内容是窗口中所有的框架。
 parent：指当前窗口的父窗口。 
 self：指当前窗口。
 top：代表当前所有窗口的最顶层窗口。
 window：代表当前窗口
```

window常用的方法有：

```
 alert：显示带有一个“确定”按钮的对话框
 confirm：显示带有“确定”与“取消”两个按钮的对话框。 
 prompt：显示带有输入区的对话框。 
 open：打开一个新窗口
 close：关闭用户打开的窗口。
```

 document常用的属性有：

```
  alinkColor：活动链接颜色。 
  linkColor：链接颜色。 
  vlinkColor：已访问过的链接颜色。
  anchors：页内链接。
  bgColor：背景颜色。 
  fgColor：前景颜色。 
  cookie：“小甜饼“。
  forms：表单元素。 
  lastModified：文档最后修改的时间。
  links：超链接。
  location：当前文档的 URL。
  referer：在用户跟随链接移动时，包含主文档的 URL 字符串值。
  title：文档标题。 
```

 document常用的方法有：

```
  write：向文档输出。
  open：打开文档。 
  close：关闭文档。
  clear：清除打开文档的内容。
```

 

 

12，js中如何定义class，如何扩展prototype？

 在面向对象编程中，类（class）是对象（object）的模板，定义了同一组对象（又称"实例"）共有的属性和方法。Javascript语言不支持"类"，但是可以用一些变通的方法，模拟出"类"。

一、构造函数法

这是经典方法，也是教科书必教的方法。它用构造函数模拟"类"，在其内部用this关键字指代实例对象。

　　

```
function Cat() {
　　　　this.name = "大毛";
　　}
```

 

生成实例的时候，使用new关键字。

　　

```
var cat1 = new Cat();
　　alert(cat1.name); // 大毛
```

 

类的属性和方法，还可以定义在构造函数的prototype对象之上。

　　

```
Cat.prototype.makeSound = function(){
　　　　alert("喵喵喵");
　　}
```

 

关于这种方法的详细介绍，请看我写的系列文章《Javascript 面向对象编程》，这里就不多说了。它的主要缺点是，比较复杂，用到了this和prototype，编写和阅读都很费力。

二、Object.create()法

为了解决"构造函数法"的缺点，更方便地生成对象，Javascript的国际标准ECMAScript第五版（目前通行的是第三版），提出了一个新的方法Object.create()。

用这个方法，"类"就是一个对象，不是函数。

　　

```
var Cat = {
　　　　name: "大毛",
　　　　makeSound: function(){ alert("喵喵喵"); }
　　};
```

 

然后，直接用Object.create()生成实例，不需要用到new。

　　

```
var cat1 = Object.create(Cat);
　　alert(cat1.name); // 大毛
　　cat1.makeSound(); // 喵喵喵
```

 

目前，各大浏览器的最新版本（包括IE9）都部署了这个方法。如果遇到老式浏览器，可以用下面的代码自行部署。

　　

```
if (!Object.create) {
　　　　Object.create = function (o) {
　　　　　　 function F() {}
　　　　　　F.prototype = o;
　　　　　　return new F();
　　　　};
　　}
```

 

这种方法比"构造函数法"简单，但是不能实现私有属性和私有方法，实例对象之间也不能共享数据，对"类"的模拟不够全面。

更多了解：http://www.ruanyifeng.com/blog/2012/07/three\_ways\_to\_define\_a\_javascript\_class.html

 

13，ajax是什么？ajax的交互模型？同步和异步的区别？如何解决跨域问题？

 

14，请给出异步加载js方案，不少于两种？

 

15，多浏览器检测通过什么？

 

16，讲述一下你所了解的前端的优化方式？

 

17，javascript中如何对一个对象进行深度clone? 

 

18，请实现，鼠标移到页面中的任意标签，显示出这个标签的基本矩形轮廓？

 

19，在页面中有如下

```
<div id="field">
	<input type="text" name="" value="UserName" />
</div>
<span class="red"></span>
```

 要求用闭包方式写一个js炒年糕文本框中取出值并在标签span中显示出来。

 

 

18和19题不会呀，，请求大家的帮忙，，给给意见和答案。