SoFunction
Updated on 2025-04-10

How to monitor text box status in real time


<div ></div>
<input type="text" name="txt" />
<script>
// Functions executed when the state changes
function handle()
{
('msg').innerHTML = ('txt').value;
}

//if("\v"=="v") returns true only in IE, including IE8
//if(/msie/()) can also be used to make a valid judgment
if("\v"=="v"){
//IE listens to the text box and assigns a function. The function name cannot be bracketed after it is named.
('txt').onpropertychange = handle;
}else{
//Google Chrome uses the Add Event Function to add events to the text box and assign the method to be executed. The same method name cannot be added with brackets after the method name.
('txt').addEventListener("input", handle);
}
</script>