The jQuery event in the processor shall not be altered



  • Hello!

    Please tell me why the variables created in the processor do not extend beyond its limits.

    For example, there's nothing going to happen:

     $('#search').on('keyup', function(){
    
     a = 'test';
    

    });

    alert(a); //ничего не выведет

    And comes out here:

     $('#search').on('keyup', function(){

     a = 'test';
     alert(a); //окно test
    

    });



  • The buttons only work when compressed. function Processor, the code that is written after - worked after Establishment Processor.

    a doesn't exist until the button is pressed. First off alertand then press any button in. #search and alert with conclusion a It's a flash.

    $('#search').on('keyup', function() {
        a = 'test';
        console.log(a); // test
    });
    

    console.log(a); // a is not defined

    $('#search').on('keyup', function() {
    a = this.value;
    f(a);
    });

    function f(a) {
    console.log(a);
    }

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js">
    </script>

    <input id='search'>


    You can declare a variable before the processor, assign a value to it in the processor and then use it anywhere.

    a = null;

    $('#search').on('keyup', function() {
    a = this.value;
    });

    $('button').click(function() {
    console.log(a);
    });

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js">
    </script>

    <input id='search'>
    <button>получить значение</button>




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2