使用类似条件jquery访问文本字段

i have few textfields in my php form. i want to handle the keypress of those textboxes in which id is ending with "-code" and "-case".How can i do it using jquery.

$('input[id$="-code"]').keypress(function() {

});

or

$('input[id$="-case"]').keypress(function() {

});

or even

$('input[id$="-code"], input[id$="-case"]').keypress(function() {

});

You can use the Attribute Ends With Selector

eg:$('input[id$="-code"], input[id$="-case"]')

You could do something like this

$('textarea[id*="-code"]', 'textarea[id*="-case"]').keypress(
    //do whatever
);

This uses the contains selector.