0

なんらかの理由でダイアログボックスが表示されません..誰かが理由を知っていますか?

jquery へのリンクが原因だと思っていましたが、問題ないように思えます。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

    <head>

        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Untitled Document</title>

        <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" />
        <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
        <script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>

        <script>
        $('#dialog').dialog({
            close: function() {
                $(this).find(':checked').each(function() {
                    var name = $(this).attr('name');
                    $('#form [name="' + name + '"]').val(true);
                });
            },
            buttons:{Close:function(){
            $(this).dialog('close');
        }
        }
        })
        </script>

    </head>

    <body>

        <form id="form">

            <div>form Box1<input type="text" name="box1"  /></div>
            <div>form Box2<input type="text" name="box2"  /></div>
            <div>form Box3<input type="text" name="box3"  /></div>

        </form>

        <div>Text fields shown for demo, use hidden in real form</div>

        <div id = "dialog">

            Box1<input type="checkbox" name="box1"  />
            Box2<input type="checkbox" name="box2"  />
            Box3<input type="checkbox" name="box3"  />

            <div>Checked boxes auto update to form on close</div>

        </div>  

    </body>
</html>

動作しているように見えるこのjsfiddleから取得 - http://jsfiddle.net/pLWzs/

助けてくれてありがとう

4

1 に答える 1

1

コードをドキュメント準備完了呼び出し内に配置する必要があります。

$(document).ready(function() {
  // Handler for .ready() called.
});

jsFiddle はこれを自動的に行いますが、独自のコードで行う必要があります。

たとえば、次のようになります。

$(document).ready(function () {
    $('#dialog').dialog({
        close: function () {
            $(this).find(':checked').each(function () {
                var name = $(this).attr('name');
                $('#form [name="' + name + '"]').val(true);
            });
        },
        buttons: {
            Close: function () {
                $(this).dialog('close');
            }
        }
    })
});

そうしないと、要素が実際に存在する前にコードが実行されます。

于 2013-03-25T17:21:38.133 に答える