


Detailed explanation of events triggered by changes in input tag content (with examples)
This article brings you a detailed explanation of the events triggered by changes in the input tag content (with examples). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
Native method
onchange event
<input>
function onc(data){ console.log(data.value); }
The onchange event is triggered when the content changes and loses focus. That is, if the focus is lost and the content does not change, it will not be triggered. If the content changes but the focus is not lost, it will not be triggered in real time.
js does not trigger when directly changing the value value
oninput event
<input>
function inp(data) { console.log(data.value) }
oninput event is triggered in real time when the input content changes. The oninput event is an event supported by most browsers except IE, and is triggered in real time when the value changes.
js is not triggered when the value is changed directly.
onpropertychange event
The onpropertychange event is triggered in real time. It will be triggered every time a character is added or deleted. This event will also be triggered by js changes, but this event is exclusive to IE.
When input is set to disable=true, it will not be triggered.
The difference between the oninput event and the onpropertychange event:
The onpropertychange event is triggered by any property change, but oninput is only triggered when the value changes. Oninput must be registered through addEventListener() , the onpropertychange registration method is the same as the general event.
Oninput is used in combination with onpropertychange
Oninput is a standard event of HTML5. It is used to detect content changes of textarea, input:text, input:password and input:search elements through the user interface. Very useful, it is triggered immediately after the content is modified, unlike the onchange event which needs to lose focus before it is triggered. The oninput event is not supported in versions below IE9 and needs to be replaced by the IE-specific onpropertychange event. This event will be triggered when the user interface changes or when the content is directly modified using a script. There are the following situations:
Modification The selected state of the input:checkbox or input:radio element is changed, and the checked attribute changes.
The value of the input:text or textarea element is modified, and the value attribute changes.
The selected item of the select element has been modified, and the selectedIndex attribute has changed.
After listening to the onpropertychange event, you can use the propertyName attribute of the event to get the changed property name.
The sample code for collecting oninput & onpropertychange to monitor input box content changes is as follows:
// Firefox, Google Chrome, Opera, Safari, Internet Explorer from version 9
function OnInput (event) { alert ("The new content: " + event.target.value); }
/ / Internet Explorer
function OnPropChanged (event) { if (event.propertyName.toLowerCase () == "value") { alert ("The new content: " + event.srcElement.value); } } <input>
When using jQuery
, you only need to bind the oninput and onpropertychange events at the same time. The sample code is as follows:
$('textarea').bind('input propertychange', function() { $('.msg').html($(this).val().length + ' characters'); });
The last thing to note is: Both oninput and onpropertychange events have a small bug in IE9, that is, they are not triggered when content is deleted through the cut and delete commands in the right-click menu, but they are normal in other versions of IE.
The above is the detailed content of Detailed explanation of events triggered by changes in input tag content (with examples). For more information, please follow other related articles on the PHP Chinese website!

The power of the JavaScript framework lies in simplifying development, improving user experience and application performance. When choosing a framework, consider: 1. Project size and complexity, 2. Team experience, 3. Ecosystem and community support.

Introduction I know you may find it strange, what exactly does JavaScript, C and browser have to do? They seem to be unrelated, but in fact, they play a very important role in modern web development. Today we will discuss the close connection between these three. Through this article, you will learn how JavaScript runs in the browser, the role of C in the browser engine, and how they work together to drive rendering and interaction of web pages. We all know the relationship between JavaScript and browser. JavaScript is the core language of front-end development. It runs directly in the browser, making web pages vivid and interesting. Have you ever wondered why JavaScr

Node.js excels at efficient I/O, largely thanks to streams. Streams process data incrementally, avoiding memory overload—ideal for large files, network tasks, and real-time applications. Combining streams with TypeScript's type safety creates a powe

The differences in performance and efficiency between Python and JavaScript are mainly reflected in: 1) As an interpreted language, Python runs slowly but has high development efficiency and is suitable for rapid prototype development; 2) JavaScript is limited to single thread in the browser, but multi-threading and asynchronous I/O can be used to improve performance in Node.js, and both have advantages in actual projects.

JavaScript originated in 1995 and was created by Brandon Ike, and realized the language into C. 1.C language provides high performance and system-level programming capabilities for JavaScript. 2. JavaScript's memory management and performance optimization rely on C language. 3. The cross-platform feature of C language helps JavaScript run efficiently on different operating systems.

JavaScript runs in browsers and Node.js environments and relies on the JavaScript engine to parse and execute code. 1) Generate abstract syntax tree (AST) in the parsing stage; 2) convert AST into bytecode or machine code in the compilation stage; 3) execute the compiled code in the execution stage.

The future trends of Python and JavaScript include: 1. Python will consolidate its position in the fields of scientific computing and AI, 2. JavaScript will promote the development of web technology, 3. Cross-platform development will become a hot topic, and 4. Performance optimization will be the focus. Both will continue to expand application scenarios in their respective fields and make more breakthroughs in performance.

Both Python and JavaScript's choices in development environments are important. 1) Python's development environment includes PyCharm, JupyterNotebook and Anaconda, which are suitable for data science and rapid prototyping. 2) The development environment of JavaScript includes Node.js, VSCode and Webpack, which are suitable for front-end and back-end development. Choosing the right tools according to project needs can improve development efficiency and project success rate.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Chinese version
Chinese version, very easy to use

SublimeText3 Linux new version
SublimeText3 Linux latest version

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
