![](/img/trans.png)
[英]Difference between document.getElementById and document.getElementsByClassName
[英]document.getElementById(s).document.getElementsByClassName error in typescript
嘗試將其與打字稿和 angular2 一起使用時
document.getElementById(s).document.getElementsByClassName
我收到這個錯誤
“錯誤”消息:“類型‘元素’上不存在屬性‘文檔’。” 在:'32,56' 來源:'ts'
我明白這是鑄造錯誤。 但是我找不到我應該將 getElementById 轉換為什么,以便它可以訪問文檔屬性
你不需要中間的document
。 getElementById()
返回的元素有自己的getElementsByClassName()
方法。
document.getElementById(s).getElementsByClassName(...)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.