Home > Web Front-end > JS Tutorial > jQuery: Solution to why select() in delegate does not work (explanation with examples)_jquery

jQuery: Solution to why select() in delegate does not work (explanation with examples)_jquery

WBOY
Release: 2016-05-16 17:02:33
Original
1132 people have browsed it

jQuery has a very useful delegate (event delegation) function, which can bind an event handling function to the current and future (dynamically added) elements.

For example, in the following example, after dynamically adding an input text box, I want all text boxes (whether dynamically added or not) to automatically turn to uppercase when they receive focus.

Copy code The code is as follows:



delegate test






  • < input type="text" value="123456abc"/>








Next, I also want to add some small functions. When getting focus, Make the text box automatically select all.
Copy code The code is as follows:

$().ready(function(){
$("#ulTarget").delegate(":text","focus",function(){
$(this).val($(this).val().toUpperCase()).select( ;

Copy code

The code is as follows:
})



Solved.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template