PHP plane question two--javascript (basic part) javascript:void (0); javlibrary.com href javascript

Source: Internet
Author: User
Second, the JavaScript part

1. JS Form Popup dialog function is? Get input focus function yes?

Popup dialog function: Alert (), Prompt (), confirm ()
Get input focus Function: Focus ()

2. JS's steering function is? How to introduce an external JS file?

Turn to usewindow.location.href = ""
Introduction of external JS use

3. Explain the meaning of the following statement: document.form["FormName"].submit. Baidu

Gets the form name FormName and submits the form data to the server. But this line of code is not able to run, there are two errors, one is to get the form by the form name to obtain the time, should be written document.forms[‘formName’] , submit form events using the Submit method, need to add parentheses, the following gives a simple sample code:

    <  form   Action  =  "a.php"   Meathod  =  "POST"   name  =  "Login"   id  =  "F1 ";  user name:  <  input   type  = " text "  name  =  "username" />   <  input   type  =  "button"   ID  =  "btn"   value  =  "commit" />  !--
     
       form 
      >   <  script   type  =  "Text/javascript" ;    Document . getElementById ( "BTN" ).  function  ()  { if  ( do Cument . forms[ ' login ' ].username.value! =  ' '  ' { document . Forms[
   
     ' login ' ].submit (); }} 
    !--
     
       script 
     ; 
    

4. Have the following statement: write code, when the mouse across the text box, automatically select the text box content. Baidu

<inputid="txt"type="text"value="baidu"/><scripttype="text/javascript">var textBox = document.getElementById('txt');    textBox.onmouseover = function(){        this.select();    }
    
     script>

5. Design a Web page so that it pops up a full-screen window with a text box and a button. The user clicks the button to close the window while entering the information in the text box, and the input information is displayed on the main page. Sina

Main window:

<ahref=""id="a1"target="new">新窗口
    
     a><divid="msg">
   
    div><scripttype="text/javascript">var a1 = document.getElementById('a1');    a1.onclick = function () {        window.open('new.html','new','location=no,toolbar=no');        returnfalse;    }
   
    script>

Pop-up window:

    <  input   type  =  "Text"   Name  =  "message"   id  =  "M1" />   <  BR />   <  input   type  =  "button"   value= "Close"   id  =  "btn" />   <  br />   <  script   Type  =  "Text/javascript" ;    var  btn =  Document    . getElementById ( ' btn ' );     var  message =  document . getElementById ( ' M1 ' ); Btn.onclick =   function  ()  { var  div =  window . Opener.document.getE        Lementbyid ( ' msg ' );        div.innerhtml = Message.value;     window . Close ();  !--
     
       script 
     ;   

6. What methods can be used to make requests to the server using JavaScript without leaving the current page, simply comparing the characteristics (if present) (cool)

Asynchronous request with XMLHttpRequest object

7. Determine if the following code is correct, if it is wrong, please indicate the error, if correct, please indicate the result of operation (Cool News)

varnewArray(    newArray(1,2,3,4),    newArray("abc""def""xyz"),);for0; i < arr.length; i++) {    document.write(arr[0]);}

Suspect that this code is wrong, the second new array after the comma is redundant, if there is no problem, then the code is correct, the output is the result of 1,2,3,4 1,2,3,4
Note : Arr is a two-dimensional array that has two elements, the first element is an array [1,2,3,4], the second element is an array of ["ABC", "Def", "XYZ"],for loop statements executed two times, but both are output first elements, i.e. arrays [ 1,2,3,4].

E 8. Write a function in JavaScript with the ability to delete duplicate elements in the array.

 <  script   type  =  "Text/javascript" ;    functionarray_unique(arr){ var result = arr;  for (var i = 0; i < arr.length; i++)                {  for (var j = 0; i < arr.length; J + +) {temp = Arr[i]; //If the current element is equal to one of the following elements, remove the top element if ((i+j+1) < arr.length && temp = = = arr[i+j+1])                {Result.splice (i+j+1,1); }}} return result; var a = [4,7,8,5,8,6,A, 7,0,false,', {}]; var b = Array_unique (a); alert (b); //4,5,8,5,6,43,0,false,[object Object]  
      Script
 >

9. Which of the following JavaScript statements produces a run error: ()

A. var obj = ();
B. var obj = [];
C. var obj = {};
D. var obj =//;
Answer: A

10. Select the expression that the result is true: ()

A. Null instanceof Object
B. Null = = undefined
C. Null = = undefined
D. Nan = = Nan
Answer: C

Each. Foo object has an att attribute, so the value of the Att property is obtained, which of the following is possible: ()

A. Foo.att
B. Foo ("Att")
C. foo["ATT"]
D. foo{"Att"}
E. foo["a" + "T" + "T"]
Answer: ACE

12. How to add an HTML element event, there are several ways, for example

(1). Attributes directly as elements, such as
(2). Using DOM Level 0 events, simple, good compatibility, such asimg.onclick = function(){}
(3). Using DOM Level 2 events, more powerful, in non-IE and other standards to browse, using AddEventListener, in IE, using attachevent to achieve.

Can JavaScript define a two-dimensional array, and if not, how can you solve it?

JavaScript does not support two-dimensional array definitions, which can be resolved with arr[0] = new Array ().

14. Assuming that a.html and b.html are under the same folder, the JavaScript implementation automatically jumps to b.html when the a.html is turned on for five seconds.

<scripttype="text/javascript">functiongo2b() {        window.location.href = "b.html";        window.close();    }    setTimeout("go2b()",5000);//5秒后自动执行go2b方法
    
     script>

15. Use JavaScript to write out three ways to produce an image tag (hint: From method, object, HTML angle)

(1).var img = new Image();
(2).var img = document.createElement("image")
(3).img.innerHTML = ""

Code for page forward and backward in JS

Forward: history.forward(); orhistory.go(1);
Back: history.back (); orhistory.go(-1);

17. Please write out a DOM tree (YG) with at least 3 nodes

<scripttype="text/javascript">var div = document.createElement("div");    var a = document.createElement("a");    a.href = "http://www.baidu.com";    var span = document.createElement("span");    span.innerHTML = "百度";    a.appendChild(span);    div.appendChild(a);    document.body.appendChild(div);
    
     script>

Result HTML:
百度

18. Implement the Code of the Click button Popup (YG)

document'button'function(){window.open ('page.html');}

Where button is the id,page.html is the window to pop up the page.

What are the basic data types included in JavaScript? Millet

JavaScript includes 5 basic data types, namely Number,string,boolean,null and Undefined.

The above describes the PHP surface of the second--javascript (the basic part), including Javascript content, I hope that the PHP tutorial interested in a friend helpful.

  • Related Article

    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.