Home Web Front-end JS Tutorial Why is the keyup event not executed in jquery?

Why is the keyup event not executed in jquery?

Jun 27, 2017 pm 02:20 PM
jquery keyup Why

I want to achieve
1. After clicking the #skillKey tr element, the code color changes,
2. Then change the text of the current element after inputting through the keyboard, for the convenience of Debugging Let’s talk about step 2 Omit it to alert(123)
HTML code code is as follows:

<table id="skillKey">
<tbody>
<tr>Q</tr>
</tbody>
<table>
Copy after login

JQueryCode is as follows:

$(function () {

    $(&#39;#skillKey&#39;).on(&#39;click&#39;, &#39;tr&#39;, function () {
        $(this).css(&#39;color&#39;,&#39;red&#39;);
        $(this).keyup(function(){
        alert(123)
        });
    });
})
Copy after login

Why does the element change color after clicking, but input through the keyboard cannot alert? The effect can indeed be achieved through $(document).keyup(). I would like to know the reason. Maybe it has something to do with the type of element that keyup() requires to be bound?

Another: A wrong keyup()functioncalling method, if written like this:

$(function () {

    $(&#39;#skillKey&#39;).on(&#39;click&#39;, &#39;tr&#39;, function () {
        $(this).css(&#39;color&#39;,&#39;red&#39;);
        $(this).keyup(alert(123));
    });
})
Copy after login

Then after clicking tr, the element changes color and a window 123 will pop up. This Why?

First point out one of your mistakes

$(&#39;#skillKey&#39;).on(&#39;click&#39;, &#39;tr&#39;, function () {
    $(this).css(&#39;color&#39;,&#39;red&#39;);
    $(this).keyup(function(){
    alert(123)
    });
});
Copy after login

You bind event like this. The result is that tr is bound once when you click it, and it is bound as many times as you click it. This example is still not obvious. You place an input in tr, and then write the following code to see the effect.

$(&#39;#skillKey&#39;).on(&#39;click&#39;, &#39;input&#39;, function () {
    $(this).css(&#39;color&#39;,&#39;red&#39;);
    $(this).blur(function(){
        alert(123)
    });
});
Copy after login

Give me some suggestions

You can first use the elements that need to be usedCache, don’t abuse $, you can use chaining if it is easy to read

$(&#39;#skillKey&#39;).on(&#39;click&#39;, &#39;tr&#39;, function () {    var $this = $(this);
    $this
        .css(&#39;color&#39;, &#39;red&#39;)
        .keyup(function () {
            alert(123)
        });
});
Copy after login


The above is the detailed content of Why is the keyup event not executed in jquery?. For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to fine-tune deepseek locally How to fine-tune deepseek locally Feb 19, 2025 pm 05:21 PM

Local fine-tuning of DeepSeek class models faces the challenge of insufficient computing resources and expertise. To address these challenges, the following strategies can be adopted: Model quantization: convert model parameters into low-precision integers, reducing memory footprint. Use smaller models: Select a pretrained model with smaller parameters for easier local fine-tuning. Data selection and preprocessing: Select high-quality data and perform appropriate preprocessing to avoid poor data quality affecting model effectiveness. Batch training: For large data sets, load data in batches for training to avoid memory overflow. Acceleration with GPU: Use independent graphics cards to accelerate the training process and shorten the training time.

deepseek why can't you log in deepseek login portal deepseek why can't you log in deepseek login portal Feb 19, 2025 pm 05:00 PM

There are a variety of reasons why DeepSeek cannot log in, including server failure, network connection issues, account disables, login credentials errors, or system updates. When you cannot enter the DeepSeek login portal, users can access the official website through https://www.deepseek.com/. If you encounter login problems, users should check the server status and troubleshoot network connection or login credential errors. If the problem persists, users should contact the DeepSeek support team for further assistance.

Why can't the Bybit exchange link be directly downloaded and installed? Why can't the Bybit exchange link be directly downloaded and installed? Feb 21, 2025 pm 10:57 PM

Why can’t the Bybit exchange link be directly downloaded and installed? Bybit is a cryptocurrency exchange that provides trading services to users. The exchange's mobile apps cannot be downloaded directly through AppStore or GooglePlay for the following reasons: 1. App Store policy restricts Apple and Google from having strict requirements on the types of applications allowed in the app store. Cryptocurrency exchange applications often do not meet these requirements because they involve financial services and require specific regulations and security standards. 2. Laws and regulations Compliance In many countries, activities related to cryptocurrency transactions are regulated or restricted. To comply with these regulations, Bybit Application can only be used through official websites or other authorized channels

Free market software app website Free market software app website Mar 05, 2025 pm 09:03 PM

This article introduces free digital asset quotation software apps and websites that can provide investors with key information such as real-time prices, price charts, transaction volume, fluctuations, market depth and news information to help investors make informed decisions. Compared with paid software, free software has the advantages of no cost, rich features, and easy operation. The article also guides users how to choose the right market software, and reminds users to pay attention to data sources, information accuracy and avoid excessive dependence, which ultimately helps investors better grasp the trends of the digital asset market. Want to know how to use free market software efficiently? Read the full text quickly!

Why is Bittensor said to be the 'bitcoin' in the AI ​​track? Why is Bittensor said to be the 'bitcoin' in the AI ​​track? Mar 04, 2025 pm 04:06 PM

Original title: Bittensor=AIBitcoin? Original author: S4mmyEth, Decentralized AI Research Original translation: zhouzhou, BlockBeats Editor's note: This article discusses Bittensor, a decentralized AI platform, hoping to break the monopoly of centralized AI companies through blockchain technology and promote an open and collaborative AI ecosystem. Bittensor adopts a subnet model that allows the emergence of different AI solutions and inspires innovation through TAO tokens. Although the AI ​​market is mature, Bittensor faces competitive risks and may be subject to other open source

gateio exchange app old version gateio exchange app old version download channel gateio exchange app old version gateio exchange app old version download channel Mar 04, 2025 pm 11:36 PM

Gateio Exchange app download channels for old versions, covering official, third-party application markets, forum communities and other channels. It also provides download precautions to help you easily obtain old versions and solve the problems of discomfort in using new versions or device compatibility.

Bitcoin: The 'barometer' of global liquidity? Bitcoin: The 'barometer' of global liquidity? Mar 04, 2025 pm 06:39 PM

The liquidity of the crypto market was tight, and Bitcoin fell again after continuing to fluctuate, hitting a low of $86,000, down nearly 20% from its peak. Bitcoin, the leader in cryptocurrency, has caused altcoins to collapse, and market sentiment has also shifted from fanaticism to panic. Is the Bitcoin bull market over? What is the future trend? These issues have attracted much attention. But Bitcoin trends are closely linked to global financial markets, and SwanBitcoin research analyst Sam Callahan's article on the relationship between Bitcoin price and global liquidity is worth reading. The core point of the article: Bitcoin price is consistent with global liquidity trends 83% of the time, which is higher than other major assets, making it an effective indicator for measuring liquidity conditions. Although Bitcoin is highly liquid in the world

BitMEX: Best option strategy after a big sell-off BitMEX: Best option strategy after a big sell-off Mar 04, 2025 pm 06:27 PM

Source: BitMEX Welcome to our weekly options Alpha series: Bitcoin has just dropped sharply, with a drop of 10%. Your portfolio is losing money and you may think, "What should you do next? Should you panic, increase your position, or do it smartly?" Options strategies can help manage risks, take advantage of possible rebounds, or generate revenue. Here are five effective strategies for post-selling scenarios, accompanied by examples, profit and loss analysis, and situational guidance. (As of this article was written, February 26, 2025, 13:06 Hong Kong time, the price of BTC was $88,584.) 1. If you are worried that Bitcoin will continue to decline in March... Practice: Buy protective put options (your insurance strategy) Assume you hold

See all articles