0

特定のテキスト ボックスが空のときに jquery/javascript ダイアログ ボックスを表示したい..以下のコードを試しましたが、動作しません..以下のコードに if() 関数を追加するにはどうすればよいですか?

      <script>

    $(document).ready(function () {

    $('#search_btn').click(function () {

        if ($('#form1.legacy_code_text.value') == "") { /// THIS DOESNT WORK I WANT THE CORRECT WAY FOR THIS LINE
            $("#dialog:ui-dialog").dialog("destroy");

            $("#dialog-confirm").dialog({
                resizable: false,
                height: 140,
                modal: true,
                buttons: {
                    "Ok": function () {

                        $('#form1').submit();



                        //*****************************************************************
                    },
                    Cancel: function () {
                        $(this).dialog("close");
                    }
                }


            });
        }
    });
});
        </script>
4

3 に答える 3

0

ここで私は上記の問題のためにビンを作りました。だから、http://codebins.com/bin/4ldqpatで試してみてください

次のスクリプトを実行するには次の手順に従います。

1)最新のjquery.jsおよびjqueryUIjavascriptファイルを含めます。

2)JQueryUICSSファイルを含めます。

3)HTML:

<div id="dialog-confirm" title="My Dialogue">
  <form id="form1" method="post">
    <div style="padding:10px;">
      Enter Text:
      <input type="text" name="legacy_code_text" id="legacy_code_text" class="textfield"/>
    </div>
  </form>
</div>

4)jQuery:

$("#dialog-confirm").dialog({
    resizable: false,
    height: 140,
    modal: true,
    buttons: {
        "Ok": function() {
            var txtarea_val = $('#form1  #legacy_code_text').val();
            if (txtarea_val != '') $('#form1').submit();
            else {
                /*show your error*/
                alert("Enter Some text..!");
                return false;
            }

        },
        Cancel: function() {
            $(this).dialog("close");
        }
    }
});
于 2012-07-16T14:26:20.233 に答える
0
if( $('#legacy_code_text').val() == "" )
于 2012-07-16T10:42:42.947 に答える
0
if ( empty(#form1.legacy_code_text.value') ) 
于 2012-07-16T10:46:20.883 に答える