简体   繁体   中英

JS: calling a function from another JS file

I want to return some values in the dda.js that have been modified in translacao.js . I want to return this values and execute the dda.js by the translacao.js file

$(document).on('click', '#trans', function () {
  var tx = parseInt($('#tx').val());
  var ty = parseInt($('#ty').val());
  translation(tx, ty);
});

function translation(tx, ty) {
  x1 = x1 + tx;
  y1 = y1 + ty;
  x2 = x2 + tx;
  y2 = y2 + ty;

  return dda(x1,y1,x2,y2);
}

I suggest you always to put your JavaScript code in a document.onload event. It is always a good usage:

document.onload = function(){
   // your code
};

In jQuery you have a better choice:

$(document).ready(function() {
// your code
});

This way your code will always be executed when the document is fully loaded, so when all the js files are loaded.

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