0

私の場合、x をグローバル変数に設定する方法は?

$(document).on( 'click', '#something', function (){
   x = $(#etc);
});


$(document).on( 'click', '#somethingElse', function (){

 alert(x) <-- unidentified here 

});

2 つの on() を一緒にバインドしても、x はまだ「通行不能」です

4

3 に答える 3

0

次のようなこともできます:

    <script type="text/javascript">

    var Test = {

        init:function() {

             $(document).on( 'click', '#something', function (){
                 Test.x = $('#etc');
             });


             $(document).on( 'click', '#somethingElse', function (){

             alert(Test.x);

             });
        }

    }

    $(document).ready(function() {
        Test.init();
    });

    </script>
于 2013-09-06T03:51:16.000 に答える