2009-08-12 83 views
0

好的我有一個網站,其中有不同的模板,每個模板有不同的htmls。 我想知道如何渲染每一行的動態與jquery分頁的部分?jquery動態模板div行建設

我不想在一個var中存儲html,因爲它隨着模板而改變,我想讓設計器變得簡單而不需要知道jquery代碼。

有沒有辦法讓我可以在每次添加一行時將div代碼和循環渲染。

<div id='id_here'>row one</div> 
<div id='id_here'>new template row, but im adding <span>created_date here</span> 

因此,我如何才能將div和相應地呈現,而無需將div保存在var中?

新增
我的意思是我從阿賈克斯得到的數據並生成它的股利,但我怎麼能知道從哪裏產生的DIV JSON數據,如果DIV是保持在不同的模板改變。

回答

0

我不太知道我理解的問題,你的意思是這樣:

//load contents of myDiv from remote server and inject it into myDiv (url,selector) 
$("#myDiv").load("/blah.php?p=3 #myDiv"); 

//load contents of hizzay.php?p=2 from remote server and inject it into anotherDiv 
$("#anotherDiv").load("/hizzay.php?p=2");  

<div id="myDiv">output from blah.php?p=3</div> 
<div id="anotherDiv">output from hizzay.php?p=2</div> 

你是什麼意思'將div保存在var'中?

http://docs.jquery.com/Ajax/load

編輯:我想我得到它(未經):

function getPage(pageNo) 
{ 
    $("#someDIv").load("/hizzay.php?p=" + pageNo); 
    return false;//just in case 
} 

$('a.page').click(function(e) { 
    e.preventDefault();//stop the link from being followed 
    getPage($(this).text()); 
}); 

The function getPage gets its argument from the text of the generated links: 

<div id="someDiv">output from hizzay.php?p=...</div> 
<a class="page" href="#">1</a>&nbsp;<a class="page" href="#">2</a> ... 
+0

請再次檢查我的職務。 :) – Basit 2009-08-12 01:31:06

+0

我已經添加了一些更多的信息。 – Basit 2009-08-12 09:42:50

0

掛鉤爲div(可能是'load')的適當事件,然後在回調中,可以在JavaScript中隨時生成代碼,通過ajax調用將其拉入,或從靜態文件中加載。然後只需將HTML彈出到div中。

JQuery Events doc

0

如果我理解正確的話,你想一些HTML裝入容器中,對不對?

如何存儲你的模板的HTML代碼的HTML文件裏面,然後加載它,你希望它被插入:

$(function(){ 
$('#container').load('path/to/mytemplate.html'); 
});