简体   繁体   English

在jquery文件中调用javascript函数

[英]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 你好,我需要调用一个javascript函数到jquery中,并且该函数来自另一个文件..我不知道该怎么做:/这在jquery文件中

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 这是js.js文件

<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 只需将fun()放在jQuery中,然后将脚本包含在js文件首先出现的同一个html文件中

Include js.js first then your jQuery code. 首先包含js.js,然后包含jQuery代码。 I will suggest make sure that while executing jQuery code your other file should be loaded. 我将建议确保在执行jQuery代码时应加载其他文件。

As you are defining fun() function globally you can call it directly. 在全局定义fun()函数时,可以直接调用它。

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();
} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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