騰訊web前端筆試題及個(gè)人答案
每道題都有答案,大多數(shù)答案親測正確。
簡答題
1.js中“5”+4=?
答案:54
2.js中void(0)=?
答案:undefined
3.js中NaN*4=?
答案:NaN
4.js中null*4.5=?
答案:0
5.js中alert(5*015===5.075)
答案:false,結(jié)果不一樣。
6.js中13>>2=? -13>>2=?
答案:3 ,-4 ,除以4,然后向下取整。
7.js中13|5=? 13&5=?
答案:按位或:13,按位與:5。
8.js中怎么獲取當(dāng)前日期的月份
答案:
[javascript]view plaincopyPRint?- <spanstyle="font-size:18px;">vardate=newDate();varmouth=date.getMonth();</span>
9.js中數(shù)組排序方法是?該方法實(shí)現(xiàn)了什么的排序算法?
答案:排序方法是sort(),實(shí)現(xiàn)了按字符排序的算法。例var arr = [1,2,55,12,88];arr.sort();//ASCII字符代碼從小到大排,arr結(jié)果為[1,12,2,55,88];
10.js中怎么判斷Chrome瀏覽器?
答案:
[Javascript]view plaincopyprint?- <spanstyle="font-size:18px;">isChrome=window.navigator.userAgent.indexOf("Chrome")!==-1;//
- 當(dāng)isChrome=true時(shí),為chrome瀏覽器</span>
11.js中var b=”hello”;a=b; 怎么顯示出a的值(貌似這題最簡單了)
答案:
[javascript]view plaincopyprint?- <spanstyle="font-size:18px;">document.write(a);</span>
12.根據(jù)以下xml請寫出對應(yīng)的json
[plain]view plaincopyprint?- <spanstyle="font-size:18px;"><xml>
- <list>
- <item>
- <id>12</id><name>張三</name>
- </item>
- <item><id>13</id><name>李四</name>
- </item>
- </list>
- </xml></span>
答案:
[javascript]view plaincopyprint?- <spanstyle="font-size:18px;">varlists=[{"id":"12","name":"張三"},{"id":"13","name":"李四"}];</span>
13.js中怎么把十進(jìn)制數(shù)123轉(zhuǎn)化成二進(jìn)制數(shù)?
答案:
[javascript]view plaincopyprint?- <spanstyle="font-size:18px;">123.toString(2);</span>
14.js中怎么才能按下回車鍵可以提交
[javascript]view plaincopyprint?- <spanstyle="font-size:18px;"><scripttype=”text/javascript”>
- document.onkeydown=function(event){
- event=event?event:window.event;
- if(event.keyCode==13){
- alert(“helloworld!”);
- }
- };
- </script></span>
編程題
1.js中var s=”tencent is sb”,編寫js使其變成tencent1 is2 sb3
[javascript]view plaincopyprint?- <spanstyle="font-size:18px;"><scripttype="text/javascript">
- vars="tencentisperfect";
- vararray=s.split("");
- s="";
- for(vari=0;i<array.length;i++){
- s+=array[i]+(i+1)+"";
- }
- document.write(s);
- </script></span>
2.編寫js的類,使其擁有public和private類型的屬性和方法
[javascript]view plaincopyprint?- <spanstyle="font-size:18px;"><scripttype="text/javascript">
- functionPerson(_name,_age,_sex,_salary){
- //public
- this.name=_name;
- this.age=_age;
- //privare
- varsex=_sex;
- varsalary=_salary;
- //publicmethod
- this.getName=function(){
- returnthis.name;
- }
- this.getAge=function(){
- returnthis.age;
- }
- //privatemethd
- functiongetSex(){
- returnsex;
- }
- functiongetSalary(){
- returnsalary;
- }
- this.display=function(){
- document.write(this.getName()+"---"+this.getAge()+"---"+getSex()+"----"+getSalary());
- }
- }
- varsmirk=newPerson("zy","21","f","5000");
- smirk.display();
- </script></span>
3.說出一些常用的網(wǎng)絡(luò)優(yōu)化工具
答:優(yōu)化大師,超級兔子SEO(Search Engine Optimization)縮寫而來, 中文意譯為“搜索引擎優(yōu)化”。SEO優(yōu)化工具:1.TrafficTravis——SEO分析工具2.Backlinkwatch.com—反鏈檢測3.XENU Link Sleuth—死鏈檢測4.SEO Tool Bar (火狐插件)5.SEO Quake (火狐插件)
面試官問的題
1.CSS的樣式在不同類型的瀏覽器之間的顯示差異如何解決答:(個(gè)人理解)先判斷為何種瀏覽器,再為不同瀏覽器加載不同的cssa. CSS中幾種瀏覽器對不同關(guān)鍵字的支持,可進(jìn)行瀏覽器兼容性重復(fù)定義 !important 可被Firefox和IE7識別 * 可被IE6、IE7識別 _ 可被IE6識別 *+ 可被IE7識別b. 應(yīng)用條件注釋(只對IE有效),因?yàn)镮E各版本的瀏覽器對我們制作的WEB標(biāo)準(zhǔn)的頁面解釋不一樣,具體就是對CSS的解釋不同,我們?yōu)榱思嫒葸@些,可運(yùn)用條件注釋來各自定義,最終達(dá)到兼容的目的。比如:
[html]view plaincopyprint?- <spanstyle="font-size:18px;"><!–默認(rèn)先調(diào)用css.css樣式表–>
- <linkrel="stylesheet"type="text/css"href="css.css"/>
- <!–[ifIE7]>
- <!–如果IE瀏覽器版是7,調(diào)用ie7.css樣式表–>
- <linkrel="stylesheet"type="text/css"href="ie7.css"/>
- <![endif]–>
- <!–[iflteIE6]>
- <!–如果IE瀏覽器版本小于等于6,調(diào)用ie.css樣式表–>
- <linkrel="stylesheet"type="text/css"href="ie.css"/>
- <![endif]–></span>
2.在css中用一行css代碼實(shí)現(xiàn)在不同類型的瀏覽器(如IE6,IE7,IE8)之間顯示出不同的樣式
[css]view plaincopyprint?- <spanstyle="font-size:18px;">.mycolor{
- color:#FFF/9;/*IE6、7、8*/
- *color:#FF0;/*IE7、6*/
- _color:#F00;/*IE6*/
- }</span>
3.頁面上有左中右三列,左右兩列列寬固定,中間列自適應(yīng),要求紙上手寫代碼
[html]view plaincopyprint?- <!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <htmlxmlns="http://www.w3.org/1999/xhtml">
- <head>
- <metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/>
- <title>三欄布局-浮動方法</title>
- <styletype="text/css">
- body,div,p{
- margin:0;
- padding:0;
- }
- #wrap{
- padding:0300px0200px;
- *overflow:hidden;
- }
- #main{
- float:left;width:100%;
- height:600px;
- background:#fffaba;
- }
- #left,#right{
- position:relative;
- height:600px;
- _display:inline;
- }
- #left{
- width:200px;
- float:left;
- margin-left:-100%;
- right:200px;
- _right:-300px;
- background:#8fc41f;
- }
- #right{
- width:300px;
- float:right;
- margin-right:-300px;
- background:#00b7ef;
- }
- </style>
- </head>
- <body>
- <spanstyle="white-space:pre"></span><divid="wrap">
- <divid="main">
- main
- </div>
- <divid="left">
- left
- </div>
- <divid="right">
- right
- </div>
- </div>
- </b