三七互娱秋招笔试 - web前端开发

1,436 阅读2分钟

$(document).ready()和window.onload()的区别

  1. 执行时间上的区别:window.onload必须等到页面内(包括图片的)所有元素加载到浏览器中后才能执行。而$(document).ready(function(){})是DOM结构加载完毕后就会执行。
  2. 编写个数不同:window.onload不能同时写多个,如果有多个window.onload,则只有最后一个会执行,它会把前面的都覆盖掉。$(document).ready(function(){})则不同,它可以编写多个,并且每一个都会执行。

私有IP的规则

根据RFC 1918私有网络地址分配 (Address Allocation for Private Internets)

a类:10.0.0.0~10.255.255.255

B类:172.16.0.0~172.31.255.255

C类:192.168.0.0~192.168.255.255

CSS哪些属性具有自动继承的属性

一、无继承性的属性

  1. 规定元素应该生成的框的类型: display

  2. 文本属性:

    vertical-align:垂直文本对齐

    text-decoration:规定添加到文本的装饰

    text-shadow:文本阴影效果

    white-space:空白符的处理

    unicode-bidi:设置文本的方向

  3. 盒子模型的属性:width、height、margin 、margin-top、margin-right、margin-bottom、margin-left、border、 border-style、border-top-style、border-right-style、border-bottom-style、border-left-style、border-width、border-top-width、border-right-right、border-bottom-width、border-left-width、border-color、border-top-color、border-right-color、border-bottom-color、border-left-color、border-top、border-right、border-bottom、border-left、padding、padding-top、padding-right、padding-bottom、padding-left

  4. 背景属性:background、background-color、background-image、background-repeat、background-position、background-attachment

  5. 定位属性:float、clear、position、top、right、bottom、left、min-width、min-height、max-width、max-height、overflow、clip、z-index

  6. 生成内容属性:content、counter-reset、counter-increment

  7. 轮廓样式属性:outline-style、outline-width、outline-color、outline

  8. 页面样式属性:size、page-break-before、page-break-after

  9. 声音样式属性:pause-before、pause-after、pause、cue-before、cue-after、cue、play-during

作用域,参数赋值,闭包

var i = 1
function a(i){
    console.log(i)
    console.log(arguments[0])
    var i = 2
    console.log(i)
    console.log(arguments[0])
}
a(10)

// 输出 10 10 2 2
var a = 1
obj = {
    a:2,
    func(){
        return this.a
    }
}

console.log(obj.func())
console.log((obj.func)())
console.log((obj.func = obj.func)())
console.log((obj.func, obj.func)())
console.log((obj.func, obj.func).call(this))

宏任务,微任务

setTimeout(function () {
    console.log(1);
}, 0);
new Promise(function (a, b) {
    console.log(2);
    for (var i = 0; i < 10; i++) {
        i == 9 && a();
    }
    console.log(3)
}).then(function () {
    console.log(4)
});
console.log(5);

// 输出 2 3 5 4 1
  • 宏任务:script, setTimeout, setInterval
  • 微任务:Promise, Process.nextTick

编程题

对象数组的去重

/**
 * 
 * @param {Array} arr 
 */
function distinctObjectArray(arr) {
    let obj = {}
    arr.forEach(e => {
        obj[JSON.stringify(e)] = e
    })
    return Object.keys(obj).map(o => JSON.parse(o))
}

股票买卖(leetcode 121.)

/**
 * 
 * @param {Array} prices 
 */
function maxProfit(prices) {
    if (prices.length < 1) return 0
    let min = prices[0]
    let max = 0
    for (price of prices) {
        min = Math.min(min,price)
        max = Math.max(max, price - min)
    }
    return max
}