2017-07-17 114 views
0

我有一个功能,切换div内的输入字段的启用/禁用状态。这个div有一个唯一的ID,div包含具有相同类名的输入。Typescript禁用具有类的特定ID内的所有元素

const el = document.getElementById('slice_' + slice).getElementsByClassName('shiftSlice'); 
     for (let i = 0; i < el.length; i++) { 
      el[i].disabled = true; 
     } 

当我尝试这一点,打字稿告诉我,[ts] Property 'disabled' does not exist on type 'Element'.

我需要以某种方式施放此元素能够访问残疾人财产?

回答

2

你需要告诉打字稿,这是一个输入元素:

const el = document.getElementById('slice_' + slice).getElementsByClassName('shiftSlice'); 
for (let i = 0; i < el.length; i++) { 
    (<HTMLInputElement>el[i]).disabled = true; // note the type assertion on the element 
} 
相关问题