简体   繁体   中英

OnInput event not working anymore

My friends, the code below used to work in Chrome till version 52.x but in the newest version it does not work anymore. Does any of you have any idea why it does not work?

https://jsfiddle.net/2jtrs2m2/

<input type="text" id="test" />

<script type="text/javascript">

var my_event = document.createEvent("TextEvent");    
my_event.initTextEvent("textInput",true,false,window,"T");

document.getElementById("test").focus();

document.getElementById("test").dispatchEvent(my_event);

</script>

Usually when I executed this code, Chrome would insert the character T in the input. I dont want to use document.getElementById("xxx").value = "T" cause in some very specific cases I am working on, I really can only use the code above firing the oninput event which for some reason is not working anymore.

Try using document.execCommand ie; document.execCommand("insertText", false, "foo");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM