2014-01-24 51 views
0

我是網絡開發新手。我正在開發一個頁面,並將其分解爲各種div元素。爲了減少數據消耗,我想更新任何事件的觸發器上只有特定div元素的內容,其餘部分應該相同。我怎樣才能做到這一點?只更新特定div元素的內容

[編輯] [代碼]

<html> 
.... 
.... 
<body> 
    <div id="post"> 
     <h1>Post tile<h1> 
     <img src="/s/smt.png"> 
     <p>this is the post desc</p> 
    <div> 
<div id="any other"> 
</div> 
. 
. 
. 
<body> 
</html> 

讓我們考慮在那裏我需要動態地更新格「後」只有在不查詢頁面的任何其他部分的上述情況。

重要編輯(@Milind Anantwar,感謝您發表此評論): 更新應該依賴於服務器。我的意思是,情況怎麼樣,我需要從我的數據庫更新DIV ..

+0

這裏是我們的代碼? – Anup

+0

Plz顯示你的代碼。 建議,您可以使用javascript(jquery)來做到這一點 – fanfan1609

+3

@ beck03076「我不知道網絡編程」並不意味着我不知道linux :) –

回答

0

你可以做這樣的事情Demo

var button = document.getElementById('b'); 
var div = document.getElementById('any_other'); 

var count = 0; 
button.addEventListener('click', function() { 
    // Updating div dynamically by click event on button 
    div.innerHTML = 'This is dynamicaaly updated - ' + count + ' times'; 
    count++; 
}); 
+0

我希望它從服務器更新,在這種情況下,我該怎麼做?:? –

+0

@devifox你應該閱讀關於ajax。使用ajax,獲取內容,使用響應更新div ... – sachinjain024