简体   繁体   中英

calling javascript function in jquery file

hello i need to call a javascript function into jquery and the function is from another file .. i don't know how to do it :/ this is in the jquery file

if ( slotNumber == cardNumber ) {
    ui.draggable.addClass( 'correct' );
    ui.draggable.draggable( 'disable' );
    $(this).droppable( 'disable' );
    ui.draggable.position( { of: $(this), my: 'left top', at: 'left top' }  );
    ui.draggable.draggable( 'option', 'revert', false );
    correctCards++;
    count ++;
    //i want to add the function here
} 

here's the js.js file

<script type = "text/javascript">
    function fun() {
        document.write("it's working");
    }
</script>

anyone have any idea how to do it ?

This is no difference from normal function call. Just put fun() in jQuery and include the scripts in the same html file where the js file comes first

Include js.js first then your jQuery code. I will suggest make sure that while executing jQuery code your other file should be loaded.

As you are defining fun() function globally you can call it directly.

if ( slotNumber == cardNumber ) {
  ui.draggable.addClass( 'correct' );
  ui.draggable.draggable( 'disable' );
  $(this).droppable( 'disable' );
  ui.draggable.position( { of: $(this), my: 'left top', at: 'left top' }  );
  ui.draggable.draggable( 'option', 'revert', false );
  correctCards++;
  count ++;
  fun();
} 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM