js面试题.docx
- 文档编号:5362918
- 上传时间:2022-12-15
- 格式:DOCX
- 页数:49
- 大小:48.47KB
js面试题.docx
《js面试题.docx》由会员分享,可在线阅读,更多相关《js面试题.docx(49页珍藏版)》请在冰豆网上搜索。
js面试题
第一题
编写一个方法求一个字符串的字节长度
第二题
如何控制alert中的换行
第三题
解释document.getElementById("ElementID").style.fontSize="1.5em"
第四题
将一个类似图中的效果分离成css和html
第五题
按照格式xxxx年xx月xx日xx时xx分xx秒动态显示时间要求不足10的补0
第六题
编写一个方法去掉一个数组的重复元素
第七题
说出3条以上ff和ie的脚本兼容问题
第八题
按要求写一个简单的ajax示例简单的没意义就不写了
1.
newfunction(s)
{
if(!
arguments.length||!
s)returnnull;
if(""==s)return0;
varl=0;
for(vari=0;i { if(s.charCodeAt(i)>255)l+=2; elsel++; } alert(l); }("hello你好,我好,大家好! world! "); 2. alert("hello\nworld"); 3. em是个相对单位。 5. newfunction() { with(newDate()) { vart=function(a){returna<10? "0"+a: a;} alert(getFullYear()+"年"+t(getMonth()+1)+"月"+t(getDate())+"日"+t(getHours())+"时"+t(getMinutes())+"分"+t(getSeconds())+"秒"); } } 6. Array.prototype.strip=function() { if(this.length<2)return[this[0]]||[]; vararr=[]; for(vari=0;i { arr.push(this.splice(i--,1)); for(varj=0;j { if(this[j]==arr[arr.length-1]) { this.splice(j--,1); } } } returnarr; } vararr=["abc",85,"abc",85,8,8,1,2,5,4,7,8]; alert(arr.strip()); 8.
varBrowser={
/**
Browser对象用于检测浏览器,其中用到了IE的条件编译
*/
/*@cc_on
isIE:
true,
@*/
isFF:
window.navigator.appName.toUpperCase().indexOf("NETSCAPE")!
=-1?
true:
false,
isOpera:
window.navigator.appName.toUpperCase().indexOf("OPERA")!
=-1?
true:
false
};
Function.prototype.bind=function(object)
{
var_this=this;
returnfunction()
{
_this.apply(object,arguments);
}
}
functionHttpRequest()
{
this.async=true;
this.cache=false;
this.xmlhttp=function()
{
if(Browser.isFF&&window.XMLHttpRequest)
{
try{
returnnewXMLHttpRequest();
}catch(e){}
}
elseif(Browser.isIE&&window.ActiveXObject)
{
varVersion=[
"Msxml2.XMLHTTP.6.0","Msxml2.XMLHTTP.5.0","Msxml2.XMLHTTP.4.0",
"Msxml2.XMLHTTP.3.0","Msxml2.XMLHTTP.2.6","Msxml2.XMLHTTP",
"Microsoft.XMLHTTP.1.0","Microsoft.XMLHTTP.1","Microsoft.XMLHTTP"
];
for(vari=0;i { try{ returnnewActiveXObject(Version[i]); }catch(e){} } } }()||false; } HttpRequest.prototype={ send: function(object,url,callback) { if(! this.xmlhttp)return; this.xmlhttp.open(object? "post": "get",url,! ! this.async); if(object)this.xmlhttp.setRequestHeader("content-type","application/x-www-form-urlencoded"); if(! this.cache) { this.xmlhttp.setRequestHeader("No-Cache","1"); this.xmlhttp.setRequestHeader("Pragma","no-cache"); this.xmlhttp.setRequestHeader("Cache-Control","no-cache"); this.xmlhttp.setRequestHeader("Expire","0"); this.xmlhttp.setRequestHeader("Last-Modified","Wed,1Jan199700: 00: 00GMT"); this.xmlhttp.setRequestHeader("If-Modified-Since","-1"); } if(! this.callback)this.callback=callback; if(! this.async) { if(typeof(this.callback)=="string") { eval(this.callback); } elseif(typeof(this.callback)=="function") { this.callback(this.xmlhttp); } } else { this.xmlhttp.onreadystatechange=function() { if(this.xmlhttp.readyState==4) { if(this.xmlhttp.status==0||this.xmlhttp.status==200) { if(typeof(this.callback)=="string") { eval(this.callback); } elseif(typeof(this.callback)=="function") { this.callback(this.xmlhttp); } } } }.bind(this); } this.xmlhttp.send(object); }, abort: function() { if(this.xmlhttp&&this.xmlhttp.abort)this.xmlhttp.abort(); } }; //ajax类定义结束 newHttpRequest().send(null,"", function(r) { document.getElementById("load").innerHTML=r.responseText.match(/ (? : \/)? >/img).join(""); }); javascript面试题汇总 1、form中的input有哪些类型? 各是做什么处理使用的? textradiocheckboxfilebuttonimagesubmitresethidden submit是button的一个特例,也是button的一种,它把提交这个动作自动集成了。 如果表单在点击提交按钮后需要用JS进行处理(包括输入验证)后再提交的话,通常都必须把submit改成button,即取消其自动提交的行为,否则,将会造成提交两次的效果,对于动态网页来说,也就是对数据库操作两次。 button具有name、value属性,能触发onclick事件 submit继承了button submit增加了触发表单onsubmit事件的功能、增加了执行表单的submit()方法的功能 INPUTtype=submit按回车提交表单 button提交的是innerTEXT 2、table标签中border,cellpaddingtd标签中colspan,rowspan分别起什么作用? border边界 cellpadding边距 cellpadding,是补白,是指单元格内文字与边框的距离 cellspacing,两个单元格之间的距离 colspan跨列数 rowspan跨行数 3、form中的input可以设置readonly和disable,请问这两项属性有什么区别? readonly不可编辑,但可以选择和复制 disable不能编辑复制选择 4、JS中的三种弹出式消息提醒(警告窗口、确认窗口、信息输入窗口)的命令是什么? alert confirm prompt 5.题目: 当点击按钮时,如何实现两个td的值互换? 用javascript实现此功能。 分析: 这个题主要是考变量传值。 其次是考如何取元素的值。 第一种代码如下: Code 1 DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http: //www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 //www.w3.org/1999/xhtml"> 3 4 5 6 7// [CDATA[ 8functionsubmitbtn(){ 9 10vartText1=document.getElementById('txt1'); 11varSubmitBtn1=document.getElementById('submitBtn1'); 12vartText2=document.getElementById('txt2'); 13varSubmitBtn2=document.getElementById('submitBtn2'); 14SubmitBtn1.onclick=function(){ 15vartemp=tText1.value; 16tText1.value=tText2.value; 17tText2.value=temp; 18}; 19SubmitBtn2.onclick=function(){ 20vartemp=tText2.value; 21tText2.value=tText1.value; 22tText1.value=temp; 23}; 24} 25window.onload=function(){ 26submitbtn(); 27} 28//]]> 29 30 31 32
33
34
35
36
37
38