JavaScript Interview Pen question (very practical)

Source: Internet
Author: User

Test time 90 minutes
One, indefinite choice question (3 points per question, a total of 30 points)
1. Declare an object, add the Name property and show method to display its name value, and the following code is correct (D)
A. var obj = [name: ' Zhangsan ', show:function () {alert (name);}];
B. var obj = {name: "Zhangsan", Show: "Alert (THIS.name)"};
C. var obj = {name: ' Zhangsan ', show:function () {alert (name);}};
D. var obj = {name: ' Zhangsan ', show:function () {alert (this.name);}};
2. The following statement about an array object is incorrect (CD)
A. Sorting the data in the array can be used with the sort function, and if the sort effect is not expected, you can add a sort function parameter
B. Reverse for the reverse arrangement of the array data
C. Add a new element to the last position of the array, you can use the Pop method
D. The Unshift method is used to remove the first element from the array
3. To display the "Already selected text box" in the status bar of the page, the following JavaScript statements are correct (a)
A. window.status= "The text box is selected"
B. document.status= "This text box is selected"
C. window.screen= "This text box is selected"
D. document.screen= "This text box is selected"
4. Click on the button on the page to open a new window, load a Web page, the following JavaScript code is feasible (AD)
A. <input type= "button" value= "new"
onclick= "Open (' new.html ', ' _blank ')"/>
B. <input type= "button" value= "new"
onclick= "window.location= ' new.html ';" />
C. <input type= "button" value= "new"
onclick= "Location.assign (' new.html ');" />
D. <form target= "_blank" action= "new.html" >
<input type= "Submit" value= "new"/>
</form>
5. Use JavaScript to output &LT;H1&GT;HELLO&LT;/H1&GT to the Web page, which is possible in the following code (BD)
A. <script type= "Text/javascript" >
document.write (</script>
B. <script type= "Text/javascript" >
document.write ("</script>
C. <script type= "Text/javascript" >
</script>
D. <script type= "Text/javascript" >
document.write ("Hello");
</script>
6. Analyze the following code:
<script type= "Text/javascript" >
function Writeit (value) {Document.myfm.first_text.value=value}
</script>
<body bgcolor= "#ffffff" >
<form name= "myFM" >
<input type= "text" name= "First_text" >
<input type= "text" name= "Second_text" onchange= "Writeit (value)" >
</form>
</body>
A. When you enter content in the second text box of the page, the contents of the first text box are unchanged when the mouse leaves the second text box
B. When you enter content in the first text box of the page, when the mouse leaves the first text box, the contents of the first text box are copied in the second text box
C. When you enter content in the second text box of the page, when the mouse leaves the second text box, the contents of the second text box are copied in the first text box
D. When you enter content in the first text box of the page, the contents of the second text box are unchanged when the mouse leaves the first text box
7. In the following JavaScript statement, (D) implements retrieving all text boxes from the form elements in the current page and emptying them all
A. for (var i=0;i< form1.elements.length;i++) {
if (form1.elements[i].type== "text")
Form1.elements[i].value= "";}
B. for (Var i=0;i<document.forms.length;i++) {
if (forms[0].elements[i].type== "text")
Forms[0].elements[i].value= "";
}
C. if (document.form.elements.type== "text")
Form.elements[i].value= "";
D. for (var i=0;i<document.forms.length; i++) {
For (Var j=0;j<document.forms[i].elements.length; j + +) {
if (document.forms[i].elements[j].type== "text")
Document.forms[i].elements[j].value= "";
}
}
8. There is a text box element (fname) in the form (Form1) that is used to enter a phone number, such as: 010-82668155, the first 3 digits are 010, followed by a "-" and a 8-digit number. Requires that when submitting a form, verify the validity of the input in the text box based on the above criteria, and (A) correctly implement the above features in the following statements
A. var str= form1.fname.value;
if (Str.substr (0,4)!= "010-" | | str.substr (4). length!=8 | |
isNaN (Parsefloat (STR.SUBSTR (4)))
Alert ("Invalid phone number!") ");
B. var str= form1.fname.value;
if (Str.substr (0,4)!= "010-" && str.substr (4). Length!=8 &&
isNaN (Parsefloat (STR.SUBSTR (4)))
Alert ("Invalid phone number!") ");
C. var str= form1.fname.value;
if (Str.substr (0,3)!= "010-" | | str.substr (3). length!=8 | |
isNaN (Parsefloat (STR.SUBSTR (3)))
Alert ("Invalid phone number!") ");
D. var str= form1.fname.value;
if (Str.substr (0,4)!= "010-" && str.substr (4). Length!=8 &&
!isnan (Parsefloat (STR.SUBSTR (4)))
Alert ("Invalid phone number!") ");
9. With regard to the regular expression declaration of the 6-digit postcode, the following code is correct (C)
A. var reg =/\d6/;
B. var reg = \d{6}\;
C. var reg =/\d{6}/;
D. var reg = new RegExp ("\d{6}");
10. For XML processing in JavaScript, the following instructions are correct (BCD)
A. XML is an Extensible markup language that is more well-formed and is an alternative to future HTML
B. XML is typically used to transmit and store data, complementing HTML, with different purposes
C. When parsing and processing XML data in JavaScript, the approach is different because browsers are different
D. In IE browser processing XML, first need to create a ActiveXObject object

Ii. Questions and Answers
1. Enumerate at least 4 objects commonly used in the browser object model BOM, and enumerate the common methods of window objects at least 5 (10 points)
Objects: Window Document location Screen History Navigator
Method: Alert () confirm () prompt () open () Close ()
2. Briefly describe the methods used to enumerate the common lookup access nodes in document Object model DOM and make a simple explanation (10 points)
document.getElementById find elements based on element IDs
Document.getelementbyname find elements based on element name
Document.getelementtagname to find elements based on the specified element name
Third, the procedure question
1, the function of the Supplementary button event, confirm that the user exits the current page, confirms the window after the confirmation; (10 points)
<script type= "Text/javascript" >
function Closewin () {
Add code here
if (confirm) are you sure you want to exit? ")){
Window.close ();
}
}
</script>
<body>
<input type= "button" value= "Close Window" onclick= "Closewin ()"/>
</body>
2, write a simple description of the HTML tags (without attributes of the start and end tags) of the regular expression, and the following string of HTML tags to remove (15 points)
var str = "<div> here is div<p> inside the paragraph </p></div>";
//
<script type= "Text/javascript" >
var reg =/<\/?\w+\/?>/gi;
var str = "<div> here is div<p> inside the paragraph </p></div>";
Alert (Str.replace (Reg, ""));
</script>
3, complete the content of the Foo () function, ask to be able to pop-up dialog box prompts the currently selected is the first few radio boxes. (10 points)
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<body>
<script type= "Text/javascript" >
function foo () {
Add code here
var rdo = Document.form1.radioGroup;
for (var i =0; i<rdo.length;i++) {
if (rdo[i].checked) {
Alert ("You selected is the first" + (i+1) + "a Radio box");
}
}

}
</script>
<body>
<form name= "Form1" onsubmit= "return foo ();"
<input type= "Radio" name= "Radiogroup"/>
<input type= "Radio" name= "Radiogroup"/>
< Input type= "Radio" name= "Radiogroup"/>
<input type= "Radio" name= "Radiogroup"/>
<input type= " Submit "/>
</form>
</body>
4, complete function showimg (), requiring the ability to dynamically update the display of a picture according to the options of the Drop-down list (15 points)
<body>
<script type= "Text/javascript"
function showimg (osel) {
//Add code here
Var str = Osel.value;
document.getElementById ("pic"). src = str+ ". jpg";
}
</script>

<br/>
<se Lect id= "sel" onchange= "showimg (This)"
<option value= "IMG1" > Urban life </option>
<option value= " Img2 "> Urban Morning Post </option>
<option value=" IMG3 "> Green Mountains </option>
</select></body>

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.