문제

JavaScript 함수를 설계했습니다 My.js 다음 코드가 포함되어 있습니다.

My.js
function display(){

  //Call to another Javascript function defined as ShowUser() in selectUser.js
  showUser(str);

 }



SelectUser.js has


 function showUser(Str){

     //Do the display

 }

이제 내 질문은 : My.js 자체에서 Showuser ()에게 전화하고 싶습니다. 누구든지 전화를하는 방법을 제안합니까? 내가 포함해야합니까?

도움이 되었습니까?

해결책

You need to have separate script tags with the src attribute set for both javascript files in your HTML document, assuming this is for an HTML page (and not an AIR app, or serverside JavaScript, or Rhino). Whatever functions you declare in the global scope in any JavaScript file you add via a script element, or inline code should be available to JavaScript in any file.

The only caveat to this is that if you use window.foo syntax to assign something to the global (window) scope in a file then, surprisingly in IE, other files will think window.foo is unassigned until JavaScript begins executing.

More Info on that last issue

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top