如何在JSP中将HTML页面加载到DIV中(没有加载)

时间:2015-05-06 23:30:12

标签: javascript jquery html jsp

有人可以就如何使其发挥作用给我建议吗?

<html>
<head>
    <script src="../js/jquery-1.9.1.js"></script>
</head>
<body>
    <div id="divpage"></div>
    <script>
      $("#divpage").load("http://localhost:3000/annotation/testuser/demo.html");
      alert( "Load was performed." );
    </script>
</body>
</html>

2 个答案:

答案 0 :(得分:2)

浏览器必须加载完整的DOM,然后才能用javascript操作它, 在Jquery中使用.ready()

$(document).ready(function()
{
    $("#divpage").load("http://localhost:3000/annotation/testuser/demo.html");

});

答案 1 :(得分:0)

将脚本块移出正文并向上移动到头部。然后,像这样包装你的JQuery:

<script>
$(document).ready(function()
{
    $("#divpage").load("http://localhost:3000/annotation/testuser/demo.html");
    alert( "Load was performed." );
});
</script>