Home >
Web Front-end >
JS Tutorial >
Compatible with Firefox and IE's onpropertychange event oninput_form effects
Compatible with Firefox and IE's onpropertychange event oninput_form effects
WBOY
Release: 2016-05-16 19:04:00
Original
1095 people have browsed it
When entering data in the text box, you can use onkeyup to detect events when the keyboard is pressed and released. onpropertychange can capture every change, and onchange needs to execute an event before it can be captured. But sometimes we input data by pasting instead of keyboard input, which requires real-time detection of changes in the text box state. onpropertychange is not supported by firefox. If you want to use it normally under firefox, you need to use the oninput attribute and addEventListener to register the event.
<script>
//当状态改变的时候执行的函数
function handle()
{document.getElementById('msg').innerHTML='输入的文字长度为:'+document.getElementById('txt').value.length;
}
//firefox下检测状态改变只能用oninput,且需要用addEventListener来注册事件。
if(/msie/i.test(navigator.userAgent)) //ie浏览器
{document.getElementById('txt').onpropertychange=handle
}
else
{//非ie浏览器,比如Firefox
document.getElementById('txt').addEventListener("input",handle,false);
}
</script>The above is the onpropertychange event method that is compatible with Firefox.
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn