2012-03-26 8 views
0

私はtextfieldを持っていますが、textfieldhold three charactesでない場合、送信ボタンを無効にしています。私が今したいことは、textfield太字の赤いの輪郭であり、まだsubmitボタンが無効になっていますが、textfieldの概要と同時にサブミットbuttonを無効にできないようです。エラーを表示するjQueryアウトラインのテキストフィールド

送信ボタンを無効にするためのコードは次のとおりですtextfieldこの機能のlength is < 3は?

任意のヘルプ

$(function() { 

     $('input[name="updateMessage"]').attr('disabled','disabled'); 
     $('input[name="selectMessageForUpdate"]').keyup(function(){ 
      if($('input[name="selectMessageForUpdate"]').val().length < 3) 
      { 
       $('input[name="updateMessage"]').attr('disabled','disabled'); 
      } 
      else 
      { 
       $('input[name="updateMessage"]').removeAttr('disabled'); 
      } 
     }); 

    }); 

答えて

0

ためthankfull attr('disabled')

とともにborder CSSプロパティは、あなたのCSSには、赤い枠を定義するクラスを追加:

textarea[name=selectMessageForUpdate].disabled { border:5px solid red } 

あなたのJSを:

$(function() { 

     $('input[name="updateMessage"]').attr('disabled','disabled'); 
     $('textarea[name="selectMessageForUpdate"]').keyup(function(){ 
      if($(this).val().length < 3) 
      { 
       $('input[name="updateMessage"]').attr('disabled','disabled'); 
       $(this).addClass('disabled'); // ADD THIS 
      } 
      else 
      { 
       $('input[name="updateMessage"]').removeAttr('disabled'); 
       $(this).removeClass('disabled'); // ADD THIS 
      } 
     }); 

    }); 

彼はテキストエリアではなく、送信ボタンのスタイルを設定したい

http://jsfiddle.net/tmjaF/8/

+0

を、これは、ボタンのために動作しますが、私は概要を説明したいと思いますはいああ'textfield'文字が' <3' @andreasの場合 – CodersSC

+0

ok私の答えを編集しました –

+0

hmmこれはまだ動作しません:/ – CodersSC

0

...私はjsのフィドルを作成し、動作しているようです。指定したマークアップでクラスをテキストエリアに追加し、入力が有効なときにそれを削除するだけです。また、入力が空白以外のものであるかどうかを確認してください。

$(function() { 
    $('input[name=updateMessage]').attr('disabled','disabled'); 
    $('input[name=selectMessageForUpdate]').keyup(function(){ 
     if($('input[name=selectMessageForUpdate]').val().length < 3) 
     { 
      $('input[name=updateMessage]').attr('disabled','disabled'); 
      $('input[name=selectMessageForUpdate]').addClass('someClass'); 
     } 
     else 
     { 
      $('input[name="updateMessage"]').removeAttr('disabled'); 
      $('input[name=selectMessageForUpdate]').removeClass('someClass'); 
     } 
    }); 

}); 
0

あなたのCSSに追加します。

input.indicated_textfield { border: 2px solid red; } 

は、JavaScriptコードにaddClassとremoveClassの行を追加します。

$(function() { 

    $('input[name="updateMessage"]').prop('disabled', true); 
    $('input[name="selectMessageForUpdate"]').keyup(function(){ 
     if($('input[name="selectMessageForUpdate"]').val().length < 3) 
     { 
      $('input[name="updateMessage"]').prop('disabled', true); 
      $('input[name="selectMessageForUpdate"]').addClass('indicated_textfield'); 
     } 
     else 
     { 
      $('input[name="updateMessage"]').prop('disabled', false); 
      $('input[name="selectMessageForUpdate"]').removeClass('indicated_textfield'); 
     } 
    }); 

}); 
+0

jquery-1.7.2.js @elaxsjを使用しています – CodersSC

+0

jQuery 1.6.1以降では、attr/removeAttrの代わりにpropメソッドを使用する必要があります。 propメソッドは1.6.1から新しく、ページがロードされた後に属性を変更するために使用されます。それに応じて私のコードを更新しました:) – elaxsj

+0

無効になっても動作しますが、 'textfield'のアウトラインは機能しません:/' CSS'がロードされていることを確認しましたが、 'textfield '@elaxsj – CodersSC

関連する問題