Home  >  Article  >  Web Front-end  >  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
WBOYOriginal
2016-05-16 17:02:331091browse

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.

Statement:
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