未来工作室前端方向第四次考核(笔试)

未来工作室前端方向第四次考核笔试题目

一、 选择题

1.   jQuery 的方法get()做什么? 

A. 使用 HTTP GET 请求从服务器加载数据

B. 返回一个对象

C. 返回存在jQuery对象中的DOM元素

D. 触发一个get AJAX请求

2.   在HTML文档对象模型(DOM)中,history对象的(   )方法用于加载历史列表中的下一个URL页面。

A. next( )

B. history( )

C. forword( )

D. go(-1)

3.   下列(  )可以使窗口显示前一个页面 。

A. back( )

B. forward( )

C. go(1)

D. go(-1)

4.   对字符串str="welcome to china"进行下列操作处理,描述结果正确的是(   )

A. str.substring(1,5)的返回值是"elcom"

B. str.length的返回值16

C. tr.indexOf("come",4)的返回值为4

D. tr.toUpperCase( )的返回值是"Welcome To China"

5.   腾讯QQ号从10000开始,目前最高位10位,(  )可以匹配QQ号(选择一项)。

A. /^[1-9][0-9]{4,10}$/

B. /^[1-9][0-9]{4,9}$/

C. /^\d{5,10}$/

D. /^\d[5,10]$/

6.   [typeof null, null instanceof Object],使用typeof ,对于这两个类型返回的结果,下面哪个是正确的()

A. ["object", false]

B. [null, false]

C. ["object", true]

D. Other

7.   var val = 'smtg';

console.log('Value is ' + (val === 'smtg') ? 'Something' : 'Nothing');

这个结果输出正确的是()

A. Value is Something

B. Value is Nothing

C. NaN

D. Other

8.   var name = 'World!';

(function () {

    if (typeof name === 'undefined') {

       var name = 'Jack';

        console.log('Goodbye ' + name);

    } else {

        console.log('Hello ' + name);

    }

})();

下列输出结果中正确的是()

A. Goodbye Jack

B. Hello Jack

C. Hello undefined

D. Hello World

9.   function showCase2(value) {

    switch(value) {

    case 'A':

        console.log('Case A');

        break;

    case 'B':

        console.log('Case B');

        break;

    case undefined:

        console.log('undefined');

       break;

    default:

        console.log('Do not know!');

    }

}

showCase(String('A'));

下列输出结果中正确的是()

A. Case A

B. Case B

C. Do not know!

D. Undefined

10.  '5' + 3 和'5' - 3 的结果是多少()

A. 53, 2

B. 8, 2

C. error

D. other

二、 填空题

1.   JavaScript是运行在___客户端______的脚本语言。

2.   jQuery中有哪些类型得选择器,写出你掌握得三种__$('ul li.active') 标签选择器,$('.class') class选择器,$('#id') id选择器_______ 

3.   在jquery中,想让一个元素隐藏,用___hide()______实现,显示隐藏的元素用___show()_____实现。

4.   在编写页面的时候,如果想要获取指定元素在当前窗口的相对偏移,用___offset_______来实现,该方法的返回值有两个属性,分别是____top______和_____left_____。

5.   分析下面的JavaScript代码,输出结果是__uden_______ 。       

var  mystring=”I am a student”;

var a=mystring.substring(9,13);

document.write(a);

三、 简答题

1.   谈谈你对this的理解。

(1)this总是指向函数的直接调用者(而非间接调用者)

(2)如果有new关键字,this指向new出来的那个对象

(3)在事件中,this指向目标元素,特殊的是 IE的attachEvent中的this总是指向全局对象window

 

2.   对JSON的了解?

 

全称:JavaScript Object Notation

JSON中对象通过“{}”来标识,一个“{}”代表一个对象,如{“AreaId”:”123”},对象的值是键值对的形式(key:value)。JSON是JS的一个严格的子集,一种轻量级的数据交换格式,类似于xml。数据格式简单,易于读写,占用带宽小。

两个函数:

JSON.parse(str)

解析JSON字符串 把JSON字符串变成JavaScript值或对象

JSON.stringify(obj) 

将一个JavaScript值(对象或者数组)转换为一个 JSON字符串

eval('('+json+')') 

用eval方法注意加括号 而且这种方式更容易被攻击

 

 

3.   现在需要给以下button绑定一个点击事件,问共有几种方法?分别是什么?

 

<button type="submit" id="test">test</button>

参考答案:

第一种

$("#test").click(function(event){

});

第二种

document.getElementById('#foo').addEventListener('click', function() {

, false);

第三种

    <button type="submit" id="test" onclick="test()">test</button>

     function test(){/* Act on the event */

第四种

$('#test').bind('click', function() {});

第五种

$( "#test" ).on( "click", function() {);

四、 程序题

1.   在jQuery中绑定click()事件后,通过$("#div").fadeIn();可以实现元素的淡入效果,通过$("#div").fadeOut();可以实现元素的淡出效果,通过$("#div").fadeToggle();可以实现元素的淡入淡出切换效果,现在有一个id为div的元素,有一个id为btn的按钮,怎么通过原生JavaScript实现对按钮的点击,实现对div的淡入与淡出的切换效果。

 

var isHide = true;

document.getElementById(‘div’). style.transition=’0.5s’;

document.getElementById(‘btn’).onclick=function(){

if(isHide){

       document.getElementById(‘div’). style.opacity=’0’;

       isHide=!isHide;

}else{

document.getElementById(‘div’). style.opacity=’1’;

isHide=!isHide;

}

}

 

2.   现在需要进行登录操作,后端配合人员给出登录提交地址’/user/login’,提交方式为‘get’,需要参数为‘userName’和‘passWord’,你可以通过form表单或ajax进行提交,如果通过表单提交,只写出HTML代码,如果通过ajax提交,只写出JavaScript代码。

 

(1)HTML

<form action=’/user/login’ method=’get’>

<input type=‘text’ name=‘userName’>

<input type=’password’ name=’password’>

<input type=’submit’/>

</form>

(2)ajax

       $.ajax({

              type: "get",

              url: "/user/login",

              data:{

                     userName:userName,

                     password:password

              },

              Sucsess:function(){

                     Console.log(‘登陆成功’)

}

Error:function(){

       Console.log(‘登陆失败’)

}

})

 

 

3.   编写函数,用于过滤一个数组内重复的元素,并用这些元素重构一个新的数组,新数组内也不能有重复元素。

传参:array[1,4,1,1,3,3,4,6,7,8,3,7,0,11,22,22];

返回值:array[0,1,3,4,6,7,8,11,22];

 

function uniq(array){

    var temp = [ ];

    for(var i = 0; i < array.length; i++){

        if(temp.indexOf(array[i]) == -1){

            temp.push(array[i]);

        }

    }

    return temp;

}

 

function uniq(array){

    array.sort();

    var temp=[array[0]];

    for(var i = 1; i < array.length; i++){

        if( array[i] !== temp[temp.length-1]){

            temp.push(array[i]);

        }

    }

    return temp;

}

 

posted @ 2019-04-28 14:30  赵超霞  阅读(610)  评论(0编辑  收藏  举报