我用queryselectorall去獲取一個dom元素集合,然而在編譯時卻報錯說property 'style' does not exist on type 'element'。在控制臺里看block集合里各個元素是有style屬性的,但是用for循環(huán)去遍歷就沒了。求各位大神指教一下,是不是要轉(zhuǎn)類型,或者是要用foreach去遍歷?用的是typescript。代碼: var winWidth = document.body.clientWidth; var height = winWidth*1.23; let block = document.querySelectorAll(".block"); for(var i=0;i<block.length;i++){ block.item(i).style.height = height + "px"; }
TS中報錯說style在element類型中不存在怎么辦
九州編程
2019-02-12 17:16:43