参数中 height:"150" 数值后少了px
审查元素看看div这个标签是否存在,然后再看看样式是否成功赋值
function div (options) {
let div = document.createElement('div')
div.style.width = options.width ? options.width : '100px'
div.style.height = options.height ? options.height : '100px'
div.style.background = options.background ? options.background : 'red'
document.body.appendChild(div)
}
div({width:'200px', height:'100px', background: 'blue'})
一楼大哥说对了 ,就是你的参数height 缺少‘px’