试卷: 腾讯2015春招web前端开发练习卷

1  jquery ajax中都支持哪些返回类型?

dataType (default: Intelligent Guess (xml, json, script, or html))

Type: String

The type of data that you're expecting back from the server. If none is specified, jQuery will try to infer it based on the MIME type of the response (an XML MIME type will yield XML, in 1.4 JSON will yield a JavaScript object, in 1.4 script will execute the script, and anything else will be returned as a string). The available types (and the result passed as the first argument to your success callback) are:

  • "xml": Returns a XML document that can be processed via jQuery.

  • "html": Returns HTML as plain text; included script tags are evaluated when inserted in the DOM.

  • "script": Evaluates the response as JavaScript and returns it as plain text. Disables caching by appending a query string parameter, "_=[TIMESTAMP]", to the URL unless the cache option is set to true. Note: This will turn POSTs into GETs for remote-domain requests.

  • "json": Evaluates the response as JSON and returns a JavaScript object. The JSON data is parsed in a strict manner; any malformed JSON is rejected and a parse error is thrown. As of jQuery 1.9, an empty response is also rejected; the server should return a response of null or {} instead. (See json.org for more information on proper JSON formatting.)

  • "jsonp": Loads in a JSON block using JSONP. Adds an extra "?callback=?" to the end of your URL to specify the callback. Disables caching by appending a query string parameter, "_=[TIMESTAMP]", to the URL unless the cache option is set to true.

  • "text": A plain text string.

  • multiple, space-separated values: As of jQuery 1.5, jQuery can convert a dataType from what it received in the Content-Type header to what you require. For example, if you want a text response to be treated as XML, use "text xml" for the dataType. You can also make a JSONP request, have it received as text, and interpreted by jQuery as XML: "jsonp text xml." Similarly, a shorthand string such as "jsonp xml" will first attempt to convert from jsonp to xml, and, failing that, convert from jsonp to text, and then from text to xml.

2 下面哪些语句可以在JS里判断一个对象oStringObject是否为String。

oStringObject instanceof String        √

typeof oStringObject == 'string'      ×

解析:

JS里面String的初始化有两种方式:直接赋值和String对象的实例化

var str = "abc";

var str = new String("abc");

通常来说判断一个对象的类型使用typeof,但是在new String的情况下的结果会是object

此时需要通过instanceof来判断


instanceof用于判断一个变量是否某个对象的实例,如var a=new Array();alert(a instanceof Array);会返回true,

同时alert(a instanceof Object)也会返回true;这是因为Array是object的子类。

再如:function test(){};var a=new test();alert(a instanceof test)会返回true。


3 常见的浏览器端的存储技术有哪些?

有时需要将网页中的一些数据保存在浏览器端,这样做的好处是,当下次访问页面时,不需要再次向服务器请求数据,直接就可以从本地读取数据。目前常用的有以下几种方法:

cookie

cookie会随着每次HTTP请求头信息一起发送,无形中增加了网络流量,另外,cookie能存储的数据容量有限,根据浏览器类型不同而不同,IE6大约只能存储2K。

Flash ShareObject

这种方式能能解决上面提到的cookie存储的两个弊端,而且能够跨浏览器,应该说是目前最好的本地存储方案。不过,需要在页面中插入一个Flash,当浏览器没有安装Flash控件时就不能用了。所幸的是,没有安装Flash的用户极少。

缺点:需要安装Flash插件。

Google Gear

Google开发出的一种本地存储技术。

缺点:需要安装Gear组件。

userData

IE浏览器可以使用userData来存储数据,容量可达到640K,这种方案是很可靠的,不需要安装额外的插件。缺点:它仅在IE下有效。

sessionStorage

使用于Firefox2+的火狐浏览器,用这种方式存储的数据仅窗口级别有效,同一个窗口(或者Tab)页面刷新或者跳转,都能获取到本地存储的数据,当新开窗口或者页面时,原来的数据就失效了。

缺点:IE不支持、不能实现数据的持久保存。

globalStorage

使用于Firefox2+的火狐浏览器,类似于IE的userData。

1 //赋值 2 globalStorage[location.hostname]['name'] = 'tugai'; 3 //读取 4 globalStorage[location.hostname]['name']; 5 //删除 6 globalStorage[location.hostname].removeItem('name');

缺点:IE不支持。

localStorage

localStorage是Web Storage互联网存储规范中的一部分,现在在Firefox 3.5、Safari 4和IE8中得到支持。

缺点:低版本浏览器不支持。

结论:
Flash shareobject是不错的选择,如果你不想在页面上嵌入Flash,可以结合使用userData(IE6+)和globalStorage(Firefox2+)和localStorage(chrome3+)实现跨浏览器。

5 下面属于javascript基本数据类型的有?

属于javascript基本数据类型的有:
string number null undefined object boolean



Array对象方法参考:

concat   方法:返回一个新数组,这个新数组是由两个或更多数组组合而成的。array1.concat([item1[,   item2[,   .   .   .   [,   itemN]]]])

join   方法   :返回字符串值,其中包含了连接到一起的数组的所有元素,元素由指定的分隔符分隔开来。arrayObj.join(separator) 与C#不同的是这里是直接通过数组调用出来返回给一个字符串.


split  方法  :返回数组 基本和C#一样  var s="1_2_3"; var ary=s.split("_"); 参数是字符串而不是字符


pop   方法   :移除数组中的最后一个元素并返回该元素。arrayObj.pop()

push   方法   :将新元素添加到一个数组中,并返回数组的新长度值。arrayObj.push([item1   [item2   [.   .   .   [itemN   ]]]])

reverse   方法   :返回一个元素顺序被反转的   Array   对象。arrayObj.reverse(   ) 注意这里是返回一个

                原来的数组而不是创建了一个新的数组.

shift   方法   :移除数组中的第一个元素并返回该元素。arrayObj.shift(   )

slice   方法   :返回一个数组的一段。arrayObj.slice(start,   [end])  

sort   方法   :返回一个元素已经进行了排序的   Array   对象。arrayobj.sort(sortfunction)  

               如果 sort()里面没有参数那么将按照字母顺序排列

               如果要用从大到小顺序排列里面需要带参数sort(function(a,b){return b-a});


splice   方法   :从一个数组中移除一个或多个元素,如果必要,在所移除元素的位置上插入新元素,返回所移除的元素。arrayObj.splice(start,   deleteCount,   [item1[,   item2[,   .   .   .   [,itemN]]]])

unshift   方法   :将指定的元素插入数组开始位置并返回该数组。arrayObj.unshift([item1[,   item2   [,   .   .   .   [,   itemN]]]]) 在IE下无效,返回undefined fox下可以



转载于:https://my.oschina.net/sheila/blog/501072

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值