如何将字符串参数传递给jQuery

时间:2015-08-19 10:54:57

标签: jquery 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>
          $.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><br><br>
      <div id="placeholder1"></div>

 </body>
 </html>

我想点击按钮来调用该函数并渲染另一个显示其他信息的脚本。我可以合并上面的两个脚本,还是我需要的? 为我不知道如何

的函数调用外部jquery脚本

我运行了代码,它只是给了我警报消息,没有别的

2 个答案:

答案 0 :(得分:0)

你可以传递它:

"myFunction('" + reportSuiteList.suites[i].REPORTSUITE_NAME + "')"
//----------^----insert a quote here.--------------------------^

答案 1 :(得分:0)

您需要在单引号中传递值

yourfunction("'"+ reportSuiteList.suites[i].REPORTSUITE_NAME+"'")