10道实用的前端笔试题_html/css_WEB-ITnose
说明:部分答案整理自网络
1、如何消除一个数组里面重复的元素(js)
方法一:新建一个数组,利用indexOf()方法判断数组中的元素在新数组中的索引值是否为-1,是则添加到新数组中,将其封装成一个函数,如下:function unique(arry){ var arry2=[]; for(i=0;i<arry1.length;i++){ if(arry2.indexOf(arry1[i])==-1){ arry2.push(arry1[i]); } } return arry2;}
function unique(arry){ var arry2=[]; for(i=0;i<arry1.length;i++){ if(arry1.indexOf(arry1[i])==i){ arry2.push(arry1[i]); } } return arry2;}
2、如何实现垂直居中(css)
方法一:利用表格的vertical-align属性,当然首先将显示方式设置为表格,如下:<div class="content"> <div class="cell"> your content </div></div>/*css*/.content{ display:table;}.cell{ display:table-cell; vertical-align:middle;}
<div class="content"> your content</div>/*css*/.content{ height:20px; line-height:20px;}
3、如何对一个绝对定位的元素实现拖拽效果(js)
为元素添加mousedown事件,并获得鼠标的坐标与元素的top、left的差值,进一步添加mousemove事件通过所求的差值和鼠标的位置重新设置top和left的值,最后添加mouseup属性,清空mousedown与mouseove事件,如下:function drag(ele){ ele.onmousedown=function(event){ var disx=event.clientX-ele.offsetLeft; var disy=event.clientY-ele.offsetTop; document.onmousemove=function(event){ ele.style.left=event.clientX-disx+"px"; ele.style.top=event.clientY-disy+"px"; }; document.onmouseup=function(){ document.onmousedown=null; document.onmousemove=null; }; }; }
4、实现ele.removeClass()的效果
removeClass()方法是jQuery中的一个方法,该方法用来移除元素一个或多个类名,当没有参数时默认移除所有类名,用原生js模拟实现,原理是利用split()方法将元素的类名转换为数组,通过数组的indexOf()方法将需要删除的类名在元类名数组中的索引值找出来,再通过splice()方法将其删除,如下:function removeClass(ele,delClassArry){ var claNameArry=ele.className.split(" "); if(delClassArry){ for(i=0;i<delClassArry.length;i++){ var index=claNameArry.indexOf(delClassArry[i]); claNameArry.splice(index,1); } }else{ claNameArry.splice(0,claNameArry.length); } var nowClass=""; for(i=0;i<claNameArry.length;i++){ nowClass+=claNameArry[i]; if(i<claNameArry.length-1){ nowClass+=" "; } } ele.className=nowClass;}
5、如何使用js判断设备类型?
利用 userAgent,userAgent的作用就是用来识别浏览器名称版本、引擎以及操作系统等信息的内容。如下:var browser = { versions:function(){ var u = navigator.userAgent, app = navigator.appVersion; return ; }(), language:(navigator.browserLanguage || navigator.language).toLowerCase()} document.writeln("语言版本: "+browser.language);document.writeln(" 是否为移动终端: "+browser.versions.mobile);document.writeln(" ios终端: "+browser.versions.ios);document.writeln(" android终端: "+browser.versions.android);document.writeln(" 是否为iPhone: "+browser.versions.iPhone);document.writeln(" 是否iPad: "+browser.versions.iPad);document.writeln(navigator.userAgent);
延伸阅读1延伸阅读2
6、类似QQ空间或微博的换肤系统换你来实现,你会怎么做?
个人认为可以准备多套皮肤的css,当用户选择换肤的时候就利用js将link的href属性值更换为目标皮肤的css7、如何在页面中插入音乐
(1)利用HTML5中的audio标签,但是IE 8以及更低的版本不支持,如下:
<audio src="songPath"></audio>
(2)利用雅虎媒体播放器,如下:
<a href="songPath"></a><srcipt type="text/javascript" src="http://mediaplayer.yahoo.com/js"></script>
8、实现一个生成随机颜色的函数
我们平常在网页中的颜色模式一般选用的是十六进制和RGB模式,以下以这两种模式自动生成颜色,(1)十六进制模式,利用Math.random()方法生成0~1的随机自然数,再乘以十六进制模式下的最大值,并利用toString()方法将其转换为十六进制的数值,如下:
function color(){ var color=Math.round(Math.random()*(16*16*16*16*16*16+16)).toString(16); if(color<=0xf){ color="00000"+color; } else if(color<=0xff){ color="0000"+color; } else if(color<=0xfff){ color="000"+color; } else if(color<=0xffff){ color="00"+color; } else if(a<=0xfffff){ color="0"+color; } color="#"+color; return color;}
(2)RGB模式,同上理,
function color(){ var r=Math.round(Math.random()*255); var g=Math.round(Math.random()*255); var b=Math.round(Math.random()*255); var color="rgb("+r+","+g+","+b+")"; return color;}
9、什么是异步?什么是轮询?
偶表示轮询真的不懂,只能google了
异步是一种通信机制,调用发出后,直接返回,因为不能立即得到结果,所以没有返回值,但是之后被调用者会通过状态、通知,或通过回调函数处理这个调用。 轮询是一种“拉”取信息的工作模式。设置一个定时器,定时询问服务器是否有信息,每次建立连接传输数据之后,链接会关闭。10、如何实现焦点轮播图效果?
实现焦点轮播图可以通过对所有的焦点设置点击事件,同时利用定时器改变其中让图片进行轮播,话不多说吧,贴上我上次实现的代码:html代码:
<div class="bisc-slider"> <ul> <li class="slide slide-01" id="slide-cur"><img src="/static/imghw/default1.png" data-src="../img/slide01-1920px.jpg" class="lazy" / alt="10道实用的前端笔试题_html/css_WEB-ITnose" ></li> <li class="slide"><img src="/static/imghw/default1.png" data-src="../img/slide02-1920px.jpg" class="lazy" / alt="10道实用的前端笔试题_html/css_WEB-ITnose" ></li> <li class="slide"><img src="/static/imghw/default1.png" data-src="../img/slide03-1920px.jpg" class="lazy" / alt="10道实用的前端笔试题_html/css_WEB-ITnose" ></li> <li class="slide"><img src="/static/imghw/default1.png" data-src="../img/slide04-1920px.jpg" class="lazy" / alt="10道实用的前端笔试题_html/css_WEB-ITnose" ></li> <li class="slide"><img src="/static/imghw/default1.png" data-src="../img/slide05-1920px.jpg" class="lazy" / alt="10道实用的前端笔试题_html/css_WEB-ITnose" ></li> </ul> <div class="dot-list"> <span class="dot"></span> <span class="dot"></span> <span class="dot"></span> <span class="dot"></span> <span class="dot"></span> </div> <span id="slide-prev"></span> <span id="slide-next"></span></div>
CSS代码:
.bisc-slider{ position:relative; height:22.083333%; overflow: hidden;}.slide{ opacity:0; z-index: 0; padding-bottom:22.083333%; width:100%; position:absolute;}.slide-01{ opacity:1; z-index: 1;}.bisc-slider ul{ padding-bottom:22.083333%;}.bisc-slider .slide img{ position:absolute; left:0; top:0; width:100%}.dot-list{ position:absolute; left:61.8%; bottom:10px; z-index: 9999999999;}.dot-list span{ display:inline-block; width:10px; height:10px; margin:3px; border-radius: 5px; background:#fff; cursor: pointer;}.dot-list span:first-child{ background:#365e7b;}#slide-prev{ background:url(../img/arl.png) no-repeat center; height:100%; width:50px; position:absolute; left:-50px; top:0; z-index: 999999999; cursor:pointer;}#slide-next{ background:url(../img/arr.png) no-repeat center; height:100%; width:50px; right:-50px; top:0; z-index:999999; position:absolute; cursor:pointer;}
JavaScript代码:
var imgArr=document.getElementsByClassName("slide");var dotArr=document.getElementsByClassName("dot");var minNum=0;var prevbtn=document.getElementById("slide-prev");var nextbtn=document.getElementById("slide-next");var btnAppear=document.getElementsByClassName("bisc-slider")[0];btnAppear.onmouseover=function(){ btnmove(prevbtn,"left",0,10); btnmove(nextbtn,"right",0,10);}btnAppear.onmouseout=function(){ btnmove(prevbtn,"left",-50,-10); btnmove(nextbtn,"right",-50,-10);}function btnmove(ele,attr,itarget,speed){ clearInterval(ele.timer); ele.timer=setInterval(function(){ var curAttr=parseInt(getStyle(ele,attr)); if(curAttr==itarget){ clearInterval(ele.timer); }else{ ele.style[attr]=curAttr+speed+"px"; } }, 20);}/*自动轮换函数*/function move(){ if(minNum==imgArr.length-1){ automove(imgArr[0],1); automove(imgArr[minNum],0); imgArr[0].id="slide-cur"; for(i=0;i<dotArr.length;i++){ dotArr[i].style.backgroundColor="#fff"; } dotArr[0].style.backgroundColor="#365e7b"; minNum=0; }else{ automove(imgArr[minNum],0); imgArr[minNum].id=""; minNum++; automove(imgArr[minNum],1); imgArr[minNum].id="slide-cur"; for(i=0;i<dotArr.length;i++){ dotArr[i].style.backgroundColor="#fff"; } dotArr[minNum].style.backgroundColor="#365e7b"; }}var timer=setInterval(move,5000);function aaa(){ timer=setInterval(move,5000);}/*焦点点击事件*/for(i=0;i<dotArr.length;i++){ dotArr[i].index=i; dotArr[i].onclick=function(){ if(imgArr[this.index].id!="slide-cur"){ for(i=0;i<dotArr.length;i++){ dotArr[i].style.backgroundColor="#fff"; } var curImg=document.getElementById("slide-cur"); dotArr[this.index].style.backgroundColor="#365e7b"; automove(imgArr[this.index],1); automove(curImg,0); curImg.id=""; imgArr[this.index].id="slide-cur"; minNum=this.index; return minNum; clearInterval(timer); var timer=setInterval(move,5000) }}}prevbtn.onclick=function(){ if(minNum==0){ automove(imgArr[minNum],0); imgArr[minNum].id=""; automove(imgArr[imgArr.length-1],1); imgArr[imgArr.length-1].id="slide-cur"; for(i=0;i<dotArr.length;i++){ dotArr[i].style.backgroundColor="#fff"; } dotArr[imgArr.length-1].style.backgroundColor="#365e7b"; minNum=imgArr.length-1; return minNum;}else{ automove(imgArr[minNum],0); imgArr[minNum].id=""; automove(imgArr[minNum-1],1); imgArr[minNum-1].id="slide-cur"; for(i=0;i<dotArr.length;i++){ dotArr[i].style.backgroundColor="#fff"; } dotArr[minNum-1].style.backgroundColor="#365e7b"; return minNum--;}}nextbtn.onclick=function(){ if(minNum==imgArr.length-1){ automove(imgArr[imgArr.length-1],0); imgArr[minNum].id=""; automove(imgArr[0],1); imgArr[0].id="slide-cur"; for(i=0;i<dotArr.length;i++){ dotArr[i].style.backgroundColor="#fff"; } dotArr[0].style.backgroundColor="#365e7b"; return minNum=0; } automove(imgArr[minNum],0); imgArr[minNum].id=""; automove(imgArr[minNum+1],1); imgArr[minNum+1].id="slide-cur"; for(i=0;i<dotArr.length;i++){ dotArr[i].style.backgroundColor="#fff"; } dotArr[minNum+1].style.backgroundColor="#365e7b"; return minNum++;}function automove(ele,itarget){ itarget=itarget*10000; clearInterval(ele.timer); ele.timer=setInterval(function(){ var cur=parseInt(getStyle(ele,"opacity")*10000); var ispeed=(itarget-cur)/9; if(ispeed>0){ ispeed=Math.ceil(ispeed); }else{ ispeed=Math.floor(ispeed); } if(cur==itarget){ clearInterval(ele.timer); }else{ ele.style.opacity=(cur+ispeed)/10000; ele.style.filter="alpha(opacity:"+cur+ispeed+")"; } },30)}function getStyle(ele,attr){ if(ele.currentStyle){ return ele.currentStyle[attr]; }else{ return getComputedStyle(ele,false)[attr]; }}

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

WebDevelopmentReliesonHtml, CSS 및 JavaScript : 1) HtmlStructuresContent, 2) CSSSTYLESIT, 및 3) JAVASCRIPTADDSINGINTERACTIVITY, BASISOFMODERNWEBEXPERIENCES를 형성합니다.

HTML은 웹 구조를 정의하고 CSS는 스타일과 레이아웃을 담당하며 JavaScript는 동적 상호 작용을 제공합니다. 세 사람은 웹 개발에서 의무를 수행하고 화려한 웹 사이트를 공동으로 구축합니다.

HTML, CSS 및 JavaScript는 웹 개발의 세 가지 기둥입니다. 1. HTML은 웹 페이지 구조를 정의하고 등과 같은 태그를 사용합니다. 2. CSS는 색상, 글꼴 크기 등과 같은 선택기 및 속성을 사용하여 웹 페이지 스타일을 제어합니다.

웹 개발에서 HTML, CSS 및 JavaScript의 역할은 다음과 같습니다. 1. HTML은 웹 페이지 구조를 정의하고, 2. CSS는 웹 페이지 스타일을 제어하고 3. JavaScript는 동적 동작을 추가합니다. 그들은 함께 현대 웹 사이트의 프레임 워크, 미학 및 상호 작용을 구축합니다.

HTML의 미래는 무한한 가능성으로 가득합니다. 1) 새로운 기능과 표준에는 더 많은 의미 론적 태그와 WebComponents의 인기가 포함됩니다. 2) 웹 디자인 트렌드는 반응적이고 접근 가능한 디자인을 향해 계속 발전 할 것입니다. 3) 성능 최적화는 반응 형 이미지 로딩 및 게으른로드 기술을 통해 사용자 경험을 향상시킬 것입니다.

HTML의 미래 트렌드는 의미론 및 웹 구성 요소이며 CSS의 미래 트렌드는 CSS-In-JS 및 CSShoudini이며, JavaScript의 미래 트렌드는 WebAssembly 및 서버리스입니다. 1. HTML 시맨틱은 접근성과 SEO 효과를 향상시키고 웹 구성 요소는 개발 효율성을 향상 시키지만 브라우저 호환성에주의를 기울여야합니다. 2. CSS-in-JS는 스타일 관리 유연성을 향상 시키지만 파일 크기를 증가시킬 수 있습니다. CSShoudini는 CSS 렌더링의 직접 작동을 허용합니다. 3. Webosembly는 브라우저 애플리케이션 성능을 최적화하지만 가파른 학습 곡선을 가지고 있으며 서버리스는 개발을 단순화하지만 콜드 스타트 문제의 최적화가 필요합니다.

웹 개발에서 HTML, CSS 및 JavaScript의 역할은 다음과 같습니다. HTML은 컨텐츠 구조를 담당하고 CSS는 스타일을 담당하며 JavaScript는 동적 동작을 담당합니다. 1. HTML은 태그를 통해 웹 페이지 구조와 컨텐츠를 정의하여 의미를 보장합니다. 2. CSS는 선택기와 속성을 통해 웹 페이지 스타일을 제어하여 아름답고 읽기 쉽게 만듭니다. 3. JavaScript는 스크립트를 통해 웹 페이지 동작을 제어하여 동적 및 대화식 기능을 달성합니다.

HTML은 웹 페이지 구조를 구축하는 초석입니다. 1. HTML은 컨텐츠 구조와 의미론 및 사용 등을 정의합니다. 태그. 2. SEO 효과를 향상시키기 위해 시맨틱 마커 등을 제공합니다. 3. 태그를 통한 사용자 상호 작용을 실현하려면 형식 검증에주의를 기울이십시오. 4. 자바 스크립트와 결합하여 동적 효과를 달성하기 위해 고급 요소를 사용하십시오. 5. 일반적인 오류에는 탈수 된 레이블과 인용되지 않은 속성 값이 포함되며 검증 도구가 필요합니다. 6. 최적화 전략에는 HTTP 요청 감소, HTML 압축, 시맨틱 태그 사용 등이 포함됩니다.
