我正在尝试更新多个<div>
而不刷新整个页面,并认为如果我使用index
循环一个数组我可以实现,但它根本不起作用。
但是当我用event[index]['fullName']
替换prevEvent
函数中的index
时,页面会更新。
如何在不刷新整个页面的情况下更新页面内容?
<script type="text/javascript" >
var index=0;
//pass php array to javascript
var event= <?php echo json_encode($event); ?>;
document.getElementById("fullName").innerHTML = event[index]['fullName'];
document.getElementById("emailAddress").innerHTML = event[index]['emailAddress'];
document.getElementById("phoneNumber").innerHTML = event[index]['phoneNumber'];
document.getElementById("childName").innerHTML = event[index]['childName'];
document.getElementById("theater").innerHTML = event[index]['theater'];
document.getElementById("movie").innerHTML = event[index]['movie'];
document.getElementById("eventDate").innerHTML = event[index]['eventDate'];
document.getElementById("eventTime").innerHTML = event[index]['eventTime'];
document.getElementById("eventType").innerHTML = event[index]['eventType'];
document.getElementById("numOfPeople").innerHTML = event[index]['numOfPeople'];
document.getElementById("partyRoomBook").innerHTML = event[index]['partyRoomBook'];
document.getElementById("partyRoomTime").innerHTML = event[index]['partyRoomTime'];
document.getElementById("description").innerHTML = event[index]['description'];
document.getElementById("specialAttention").innerHTML = event[index]['specialAttention'];
function prevEvent(){
index--;
document.getElementById("fullName").innerHTML = event[index]['fullName'];
}
</script>