javascript筆試題

來源:互聯網
上載者:User

第一題
編寫一個方法 求一個字串的位元組長度
第二題
如何控制alert中的換行
第三題
解釋document.getElementById("ElementID").style.fontSize="1.5em"
第四題
將一個類似圖中的效果分離成css和html
第五題
按照格式 xxxx年xx月xx日xx時xx分xx秒動態顯示時間 要求不足10的補0
第六題
編寫一個方法 去掉一個數組的重複元素
第七題
說出3條以上ff和ie的指令碼相容問題
第八題
按要求寫一個簡單的ajax樣本 簡單的沒意義 就不寫了
轉貼請註明 : http://www.pghome.net 志遠工作室
1.

<script language="javascript" type="text/javascript">
new function(s)
{
if(!arguments.length||!s) return null;
if(""==s) return 0;
var l=0;
for(var i=0;i<s.length;i++)
{
if(s.charCodeAt(i)>255) l+=2;
else l++;
}
alert(l);
}("hello你好,我好,大家好!world!");
</script>

2.

<script language="javascript" type="text/javascript">
alert("hello\nworld");
</script>

3.

em是個相對單位。

5.

<script language="javascript" type="text/javascript">
new function()
{
with(new Date())
{
var t=function(a){return a<10?"0"+a:a;}
alert(getFullYear()+"年"+t(getMonth()+1)+"月"+t(getDate())+"日"+t(getHours())+"時"+t(getMinutes())+"分"+t(getSeconds())+"秒");
}
}
</script>

6.
轉貼請註明 : http://www.pghome.net 志遠工作室
<script language="javascript" type="text/javascript">
Array.prototype.strip=function()
{
if(this.length<2) return [this[0]]||[];
var arr=[];
for(var i=0;i<this.length;i++)
{
arr.push(this.splice(i--,1));
for(var j=0;j<this.length;j++)
{
if(this[j]==arr[arr.length-1])
{
this.splice(j--,1);
}
}
}
return arr;
}
var arr=["abc",85,"abc",85,8,8,1,2,5,4,7,8];
alert(arr.strip());
</script>

8.

<html>
<head><title>loading</title></head>
<body>
<div id="load">資料正在載入......</div>
<script type="text/javascript">
var Browser={
/**
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;
return function()
{
_this.apply(object,arguments);
}
}
function HttpRequest()
{
this.async=true;
this.cache=false;
this.xmlhttp=function()
{
if(Browser.isFF&&window.XMLHttpRequest)
{
try{
return new XMLHttpRequest();
}catch(e){}
}
else if(Browser.isIE&&window.ActiveXObject)
{
var Version = [
"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(var i=0;i<Version.length;i++)
{
try{
return new ActiveXObject(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, 1 Jan 1997 00:00:00 GMT");
this.xmlhttp.setRequestHeader("If-Modified-Since","-1");
}
if(!this.callback) this.callback=callback;
if(!this.async)
{
if(typeof(this.callback)=="string")
{
eval(this.callback);
}
else if(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);
}
else if(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類定義結束
new HttpRequest().send(null,"http://ww.baidu.com",
function(r)
{
document.getElementById("load").innerHTML=r.responseText.match(/<img.*?(?:\/)?>/img).join("");
});
</script>
</body>
</html>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.