0

aspページでjqueryを使用してフォームの入力時に送信ボタンを有効または無効にします。ユーザーが必要なすべてのフィールドに入力したときに、ボタンを有効にしてaspページのボタンのクラスを変更したいのですが、多くのコードを見つけましたが、1つも私の仕事ではありません。

(function() {
    $('form > input').keyup(function() {

        var empty = false;
        $('form > input').each(function() {
            if ($(this).val() == '') {
                empty = true;
            }
        });

        if (empty) {
            $('#register').attr('disabled', 'disabled'); // updated according to http://stackoverflow.com/questions/7637790/how-to-remove-disabled-attribute-with-jquery-ie
        } else {
            $('#register').removeAttr('disabled'); // updated according to http://stackoverflow.com/questions/7637790/how-to-remove-disabled-attribute-with-jquery-ie
        }
    });
})()
4

1 に答える 1

0

これを試してください http://jsfiddle.net/5QJvK/2/

$(function(){
   $('form > input.field').keyup(function() {
        var empty = false;
        $('form > input.field').each(function() {
            if ($(this).val() == '') {
                empty = true;
            }
        });
        if (empty) {
            $('form input[type=submit]').attr('disabled', 'disabled');
        } else {
            $('form input[type=submit]').removeAttr('disabled');
        }
    });
});
于 2013-01-07T08:28:09.003 に答える