文本框类Onchange事件侦听器不能与多个类一起使用 [英] Textbox Class Onchange Event Listener Not Working with Multiple Classes

查看:95
本文介绍了文本框类Onchange事件侦听器不能与多个类一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<input class="item-quantities valid" data-bomid="1939" data-rid="2054" id="AddedItemIDs_1939_" name="AddedItemIDs[1939]" onkeypress="return isNumberKey(event)" type="text" value="7" aria-invalid="false">

无法使它正常工作.我尝试过的...

Can't get this to work. What I've tried...

$('.item-quantities, .valid').change(function () {
            alert("we are here");
});

或...

$('.item-quantities.valid').change(function () {
            alert("we are here");
});

或...

$('.item-quantities').change(function () {
            alert("we are here");
});

...以及其他一些变体.

... and a few other variations.

似乎无法弄清楚如何触发此事件.我一直在玩$('.item-quantities,.valid')的各种变体,但无济于事.正确的方法是什么?

Can't seem to figure out how to trigger this event. I've been playing around with various variations of $('.item-quantities, .valid'), to no avail. What is the correct way to do this?

推荐答案

<!DOCTYPE html>
<html>
    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
        <script>
        $( document ).ready(function() {
            $(".item-quantities").change(function () {
                        alert("we are here");
            });
        });

        </script>
    </head>
    <body>

        <input id="items" class="item-quantities valid" type="text">
    </body>
<html>

这将为课堂做好窍门

这篇关于文本框类Onchange事件侦听器不能与多个类一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆