用jquery更新div

时间:2015-03-04 09:48:19

标签: javascript jquery html css

我有以下脚本。有了这个我试图更新jsp页面中的div“右”。它包含在一个文件中。它似乎没有更新。谢谢你的帮助。

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>

<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.1.min.js"></script>

<script>
    $(document).ready(function() {
        $('#right').load('score.jsp');

    setInterval(function() {
        $('#right').load('score.jsp');
    }, 10000);
    });
</script>

</head>
<body bgcolor="c2f2bd">

更新                  

已移至文件score.jsp

        <img class="small" src="VTVFile1.jpg" alt="Image not found" onError="this.onerror=null;this.src='demo.jpg';" />
        <img class="small" src="VTVFile2.jpg" alt="Image not found" onError="this.onerror=null;this.src='demo.jpg';" />

        <img class="small" src="VTVFile3.jpg" alt="Image not found" onError="this.onerror=null;this.src='demo.jpg';" />
        <img class="small" src="VTVFile4.jpg" alt="Image not found" onError="this.onerror=null;this.src='demo.jpg';" />

</body>
</html>

1 个答案:

答案 0 :(得分:2)

您当前的代码只是在load div上引发#right事件。如果要加载内容,则需要指定发出请求的位置,例如:

$('#right').load('/foo/bar/content.php');

  

现在,内容首次加载前需要X秒。有没有办法在第一次加载时使内容可见,然后按间隔刷新?

$(document).ready(function() {
    $('#right').load('/foo/bar/content.php'); // on load

    setInterval(function() {
        $('#right').load('/foo/bar/content.php'); // every 3 seconds
    }, 3000);
});