Setting an oninput event using Javascript

HTML5 oninput event is supported by some modern browsers, including Firefox 3.X

However, oddly enough, it only works with built-in javascript:

<input id = "q" oninput="alert('blah')"> 

When I try to install it using javascript code, it fails.

 var q = document.getElementById("q"); q.oninput = function(){alert("blah");}; 

Is this just a bug in Firefox, or is there some reason?

+8
javascript html5 firefox javascript-events
source share
1 answer

After downloading FireFox v3.6.27 and performing some tests and searching. I found that my previous answer was wrong.

I got:

The oninput event property has been supported in Firefox since version 4.

So, to add an event listener in this case, you can do either

 <input id = "q" oninput="alert('blah')"> 

or

 q.addEventListener('input', function(){alert("blah");}, true); 

But I prefer a later way. You can find the reasons in addEventListener .
Also a similar feature in IE attachEvent .

+11
source share

All Articles