Baidu Front desk JS pen questions and Answers _javascript tips

Source: Internet
Author: User
Tags class definition eval
First question.
Write a method to find the byte length of a string
Second question
How to control line wrapping in alert
Question number three.
Explain document.getElementById ("ElementID"). Style.fontsize= "1.5em"
Question fourth.
Separate the effects in a similar diagram into CSS and HTML
Question fifth.
In accordance with the format XXXX xx month xx days xx, xx seconds dynamic display time requirements less than 10 of the 0
Question sixth.
Write a method to remove the repeating element of an array
Question seventh.
Say 3 more scripting compatibility issues with FF and IE
Question eighth.
Write a simple Ajax example as required simple and meaningless.
Answer
First question code:
<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, I'm good, everybody!) World! "); </script>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

Question number two: line wrapping in alert \ n
<script language= "javascript" type= "Text/javascript" > Alert ("Hello\nworld"); </script>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

The third question: EM is a relative unit.
I will not do the fourth question.
Question Fifth code:
<script language= "javascript" type= "Text/javascript" > New function () {with (New Date ()) {var t =function (a) {return a<10? " 0 "+A:A;} Alert (getFullYear () + "year" +t (GetMonth () +1) + "Month" +t (GetDate ()) + "Day" +t (GetHours ()) + "Time" +t (getminutes ()) + "Min" +t ( Getseconds ()) + "seconds"); }} </script>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

Question Sixth code:
<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]) {T His.splice (J--, 1); }} return arr; var arr=["abc", "abc", "85,8,8,1,2,5,4,7,8"; Alert (Arr.strip ()); </script>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

Question seventh: Agree Winter, another: IE have children,ff no, ie have parentelement,ff no, ie have innertext,outertext,outerhtml,ff not; FF has htmlelement, Htmldivelement,xmldocument,documentfragment,node,event,element and so on, ie did not have data island, FF did not, IE and FF to create a HttpRequest instance of the same method. Wait a minute..
Question Eighth code:
<ptml> <pead><title>loading</title></pead> <body> <div id= "Load" > data is loading ......</div> <script type= "Text/javascript" > var browser={/** Browser object is used to detect browsers, which use the conditional compilation of IE *//////* @cc_on isie:true, @*/isFF:window.navigator.appName.toUpperCase () indexOf ("NETSCAPE")!=-1?true:fa LSE, 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 "," Ms XML2. XMLHTTP "," microsoft.xmlhttp.1.0 "," MICROSOFT.XMLHTTP.1 "," Microsoft.XMLHTTP "]; for (Var i=0;i<version.length;i++) {try{return new ActiveX Object (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 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.call back); 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 (); } }; The Ajax class definition ends the new HttpRequest (). Send (NULL, "http://bbs.51js.com/index.php", function (r) {document.getElementById ("Load"). Innerhtml=r.responsetext.match (//img). Join (""); }); </script> </body> </ptml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

That's serious. The first question function defines the best parenthesis
It seems that only the expression can be without parentheses (want to show: P)
Another eighth, you're exaggerating, that's probably it.
Oxmlhttprequest=new XMLHttpRequest ();
Oxmlhttprequest.open ("Post", "/xxx.php", True)
Oxmlhttprequest.onreadystatechange=function ()
{
if (oxmlhttprequest.readystate!=4) continue;
alert (Oxmlhttprequest.responsetext);
Oxmlhttprequest.onreadystatechange=null;
Oxmlhttprequest=null;
}
Oxmlhttprequest.send ("Domain=baidu");

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.