How to unify jscript?

0

I have these two javascript , which I must place in several pages.

How can I unify them in the same js ? if it is possible such a thing. The reason for wanting to unify it is only due to the fact that both js execute within themselves the function "copyData ();" and I do not think it's a good practice to I've done it.

<script type="text/jscript"> 

    $(".NHC").on('change'  ,function(){       

        copyData();
    });
</script>

<script type="text/jscript"> 
     $(document).on('click','input[type="image"]',function(ev)
     {
         if (!$(ev.target).is('#ib_check_horario')) {

             copyData();                   
          }             
    });
</script>
    
asked by Emerson Rios 12.09.2018 в 20:50
source

1 answer

1

Of course you can just put it like this:

<script type="text/jscript"> 

  function copyData(){
    alert('soy copyData function')
  }

  $(".NHC").on('change', function() {       
     copyData();
  });

  $(document).on('click','input[type="image"]',function(ev) {
     if (!$(ev.target).is('#ib_check_horario')) {
       copyData();                   
     }             
  });

</script>
    
answered by 12.09.2018 / 20:58
source