Detect enter in input elements of a certain class

前端 未结 3 987
陌清茗
陌清茗 2021-02-19 19:57

I need to detect when someone hits \"enter\" in text inputs with a specific class.

My jQuery is as follows:

$(\'input.large\').keypress(function (e) {
           


        
3条回答
  •  借酒劲吻你
    2021-02-19 20:17

    Thanks David Rodrigues for your explanation. It helped a lot. I had to upgrade my JQuery library and the .live() function stopped to work properly.

    You can use it to the following

    Select all check box inputs of a form when click on select_all_checkboxes input type checkbox:

    jQuery(document).on("click", "#select_all_checkboxes", function(){
        var chk = this.checked;
        $('input[id=selectAll]').each(function(){
            this.checked = chk;
        });
    });
    

    Call a function "checkMail" when the user left the field using tab ou clicking of the any field that has a class name "email":

    jQuery(document).on("blur", 'input.email', function(event){
        var email = $(this).val();
        if (!checkMail(email)) {
            alert("Invalid email.");
            $(this).focus();
        }
    });
    

提交回复
热议问题