如何调用外部jQuery

如何调用外部jQuery,jquery,html,Jquery,Html,我想在点击按钮时调用MyFunction。我如上所述进行了尝试,但myfunction仅显示警报消息。一种选择是放置 用MyFunction在html文件中编写脚本,并在单击按钮时调用该文件,但我不知道如何操作。 请帮助创建您自己的脚本,打开记事本并放入所有JavaScript内容,不要在此处使用并将其保存为myscript.js 在HTML文件中,将其包括为: <!DOCTYPE html> <html> <head> <

我想在点击按钮时调用MyFunction。我如上所述进行了尝试,但myfunction仅显示警报消息。一种选择是放置 用MyFunction在html文件中编写脚本,并在单击按钮时调用该文件,但我不知道如何操作。
请帮助

创建您自己的脚本,打开记事本并放入所有JavaScript内容,不要在此处使用并将其保存为myscript.js

在HTML文件中,将其包括为:

<!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8" />
        <link rel="stylesheet" type="text/css" href="/Users/skhare/myFirstStyleSheet.css">

        <script src="http://code.jquery.com/jquery-1.7.1.min.js"> </script>

        <script>
                function myFunction(a)
                {
                    window.alert("hi " + a);
                    $.getJSON('/Users/skhare/tableList.json', function(tableList) {
                        var output="<table id=tableStyle>";
                        output+="<tr>" + "<th>" + "Table Names" + "</th>" + "</tr>";
                        for (var i in tableList.t)
                        {
                            output+="<tr>" + "<td>" + "<a href=/Users/skhare/tableDescription.html>" + tableList.t[i].name + "</a>" + "</td>" + "</tr>";
                        }

                        output+="</table>";
                        document.getElementById("placeholder1").innerHTML=output;
                    });
                }
        </script>
        <script>
          $(document).ready(function(){
            $.getJSON('/Users/skhare/reportSuiteList.json', function(reportSuiteList) {
              var output="<table id=tableStyle>";
              output+="<tr>" + "<th>" + "id" + "</th>" + "<th>" + "name" + "</th>" + "<th>" + "stage" + "</th>" + "<th>" + "DWH" + "</th>" + "</tr>";
              for (var i in reportSuiteList.suites)
              {
                output+="<tr>" + "<td>" + reportSuiteList.suites[i].REPORTSUITE_ID + "</td>" + "<td>" + 
                "<button class=\"report-suites\" id =\""+ reportSuiteList.suites[i].REPORTSUITE_NAME+ "\" onclick= \"myFunction(\'" + reportSuiteList.suites[i].REPORTSUITE_NAME + "\')\">"+reportSuiteList.suites[i].REPORTSUITE_NAME + "</button>" +
                "</td>" + "<td>" + reportSuiteList.suites[i].STAGING_DATABASE + "</td>" + "<td>" + reportSuiteList.suites[i].DWH_DATABASE + "</td>" + "</tr>";
              }

              output+="</table>";
              document.getElementById("placeholder").innerHTML=output;
            });
          });
          </script>
      </head>

      <body>
          <div id="placeholder"></div>
          <br><br><br>
          <div id="placeholder1"></div>

      </body>
      </html>
根据您的问题,myscript.js的内容应仅包括以下内容:

$(document).ready(function () {
  // All your code here...
});
头上的标签
$(document).ready(function () {
  // All your code here...
});
function myFunction(a)
{
  window.alert("hi " + a);
  $.getJSON('/Users/skhare/tableList.json', function(tableList) {
    var output="<table id=tableStyle>";
    output+="<tr>" + "<th>" + "Table Names" + "</th>" + "</tr>";
    for (var i in tableList.t)
    {
      output+="<tr>" + "<td>" + "<a href=/Users/skhare/tableDescription.html>" + tableList.t[i].name + "</a>" + "</td>" + "</tr>";
    }

    output+="</table>";
    document.getElementById("placeholder1").innerHTML=output;
  });
}
$(document).ready(function(){
  $.getJSON('/Users/skhare/reportSuiteList.json', function(reportSuiteList) {
    var output="<table id=tableStyle>";
    output+="<tr>" + "<th>" + "id" + "</th>" + "<th>" + "name" + "</th>" + "<th>" + "stage" + "</th>" + "<th>" + "DWH" + "</th>" + "</tr>";
    for (var i in reportSuiteList.suites)
    {
      output+="<tr>" + "<td>" + reportSuiteList.suites[i].REPORTSUITE_ID + "</td>" + "<td>" + 
        "<button class=\"report-suites\" id =\""+ reportSuiteList.suites[i].REPORTSUITE_NAME+ "\" onclick= \"myFunction(\'" + reportSuiteList.suites[i].REPORTSUITE_NAME + "\')\">"+reportSuiteList.suites[i].REPORTSUITE_NAME + "</button>" +
        "</td>" + "<td>" + reportSuiteList.suites[i].STAGING_DATABASE + "</td>" + "<td>" + reportSuiteList.suites[i].DWH_DATABASE + "</td>" + "</tr>";
    }

    output+="</table>";
    document.getElementById("placeholder").innerHTML=output;
  });
});