使用jQuery从一个html页面链接到另一个页面

时间:2015-08-18 04:42:49

标签: jquery html

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

  <script>
    $(document).ready(function() {
    $('#name').click(showTables(a){                
                        alert(a);
    });
    });

  </script>
</head>

<body>s
    <div id="placeholder"></div>
    <script src="http://code.jquery.com/jquery-1.7.1.min.js"></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>" + "<a href=# id = name onClick = showTables(reportSuiteList.suites[i].name>" + reportSuiteList.suites[i].REPORTSUITE_NAME + "</a>" + "</td>" + "<td>" + reportSuiteList.suites[i].STAGING_DATABASE + "</td>" + "<td>" + reportSuiteList.suites[i].DWH_DATABASE + "</td>" + "</tr>";
    }

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

});         

</body>
</html>

我得到错误的错误)在参数list.i检查了它之后但是我的(,{似乎是平衡的,我无法弄清楚我错过的地方)。 请帮忙

1 个答案:

答案 0 :(得分:1)

jQuery不是必需的,window.location.replace(...)将最好地模拟HTTP重定向。

这比使用window.location.href =更好,因为replace()没有将原始页面放在会话历史记录中,这意味着用户不会陷入永无止境的后退按钮惨败。如果要模拟某人点击链接,请使用location.href。如果要模拟HTTP重定向,请使用location.replace.

例如:

// similar behavior as an HTTP redirect
window.location.replace("http://stackoverflow.com");

// similar behavior as clicking on a link
window.location.href = "http://stackoverflow.com";