Special Exercise 12

Table of contents

1. Multiple choice questions

    1. Define var a="40" and var b=7 in JavaScript, then execute a%b to get?

    2. Which of the following options is related to the browse list ( )

    3. Which of the following statements can find sibling elements of all elements in jQuery?

    4. How to prevent the default behavior of IE and major browsers ( )

2. Programming questions

    1. Please complete the JavaScript function to return the week corresponding to the number parameter in the form of a string.


1. Multiple choice questions

1. Define var a="40" and var b=7 in JavaScript, then execute a%b to get?

A、5

B、"5"

C、undefined

D、null

Correct answer: A Your answer: D

Parse:

(1) Javascript is a weakly typed language , but obviously the string "40" cannot be used for the % operator, so it will be converted according to the following type, and the final result is 5

(2) In the operation, the + sign, the number is implicitly converted into a string . The rest of the operators are strings implicitly converted to numbers


2. Which of the following options is related to the browse list ( )

A、window,location

B、location,history

C、navigator,window

D、historylist,location

Correct answer: B Your answer: D

Parse:

(1) Objects related to the browse list: history screen location Navigator

(2) Built-in objects of the BOM browser object model: 
① window object: The core object of BOM is window , which represents an instance of the browser, and it is also a Globle object specified by ECMAScript
② location object: related to the url address , the common attributes are hash, protocol, host, hostname, pathname, port, search, href 
③ history object: store the list of recently visited URLs (that is, historical access records ), mostly used to operate the browser's "forward" and "back"
④ navigator object: Through this object, you can get the browser type, version number and other attributes of the viewer
⑤ screen object: used to store the display information of the viewer's system, such as screen resolution, color depth , etc.

(3) More detailed introduction

Window object https://www.w3school.com.cn/jsref/dom_obj_window.asp


3. Which of the following statements can find sibling elements of all elements in jQuery?

A、eq(index)

B、find(expr)

C、siblings([expr])

D、next()

Correct answer: C Your answer: B

Parse:

(1) siblings peers, find juniors, eq number, next next

① The siblings() method returns all sibling elements of the selected element

② The next() method returns the next sibling element of the selected element

③ The find() method returns the descendant elements of the selected element, all the way down to the last descendant


4. How to prevent the default behavior of IE and major browsers ( )

A、window.event.cancelBubble = true;

B、window.event.returnValue = false;

C、event.stopPropagation();

D、event.preventDefault();

Parse:

event.preventDefault() can only prevent Firefox and Google, and event.returnValue = false can also prevent IE

Prevent default event: e.preventDefault(), e.returnValue = false (IE)

Stop bubbling: e.stopPropagation(), e.cancelBubble = true (IE)


2. Programming questions

1. Please complete the JavaScript function to return the week corresponding to the number parameter in the form of a string.

Example: 1. _getday(1) -> "Monday" 2. _getday(7) -> "Sunday"

Parse:

(1) Use object storage and return value

<script>
    let value = 7
    function _getday(value) {
        const obj = {
            1: '星期一',
            2: '星期二',
            3: '星期三',
            4: '星期四',
            5: '星期五',
            6: '星期六',
            7: '星期天'
        }
        return obj[value]
    }
    console.log(_getday(value));
</script>

(2) Use the switch() method to return the value

<script>
    let value = 7
    function _getday(value) {
        switch (value) {
            case 1:
                return '星期一'
            case 2:
                return '星期二'
            case 3:
                return '星期三'
            case 4:
                return '星期四'
            case 5:
                return '星期五'
            case 6:
                return '星期六'
            case 7:
                return '星期天'
        }
    }
    console.log(_getday(value));
</script>

(3) Array storage is used, and the return value of the template string ``

<script>
    let value = 7
    function _getday(value) {
        const arr = ['一','二','三','四','五','六','天']
        return `星期${arr[value - 1]}`
    }
    console.log(_getday(value));
</script>

Guess you like

Origin blog.csdn.net/qq_51478745/article/details/131394892