contenteditable change events

前端 未结 19 2313
粉色の甜心
粉色の甜心 2020-11-22 01:36

I want to run a function when a user edits the content of a div with contenteditable attribute. What\'s the equivalent of an onchange

19条回答
  •  灰色年华
    2020-11-22 02:06

    In Angular 2+

    Value
    
    @Component({
      ...
    })
    export class ContentEditableComponent {
    
     ...
    
     type(event) {
       console.log(event.data) // <-- The pressed key
       console.log(event.path[0].innerHTML) // <-- The content of the div 
     }
    }
    
    
    

提交回复
热议问题