<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>jTemplates</title>
</head>
<body>
<div id="result"></div>
<div id="foreachResult"></div>
</body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script src="http://jtemplates.tpython.com/jquery-jtemplates_uncompressed.js"></script><BR>
<BR><script type="text/template" id="foreach">
<table>
<thead>
<tr>
<td>Index</td>
<td>ID</td>
<td>Name</td>
<td>Age</td>
<td>Mail</td>
</tr>
</thread>
<tbody>
{#foreach $T.table as record begin=1}
<tr>
<td>{$T.record$index}</td>
<td>{$T.record.id}</td>
<td>{$T.record.name}</td>
<td>{$T.record.age}</td>
<td>{$T.record.mail}</td>
</tr>
{#/for}
</tbody>
</table>
</script>
<script>
$(function($) {
var data = {
name: 'User list',
list_id: 6,
table: [
{ id: 1, name: 'Alex', age: 21, mail: '[email protected]' },
{ id: 2, name: 'Amelie', age: 24, mail: '[email protected]' },
{ id: 3, name: 'Polly', age: 18, mail: '[email protected]' },
{ id: 4, name: 'Alice', age: 26, mail: '[email protected]' },
{ id: 5, name: 'Martha', age: 25, mail: '[email protected]' }
]
};
var mydata = { name: "Alex", age: "21" };
$("#result").setTemplate("My name is {$T.name}"); $("#result").processTemplate(mydata);
$('#foreachResult').setTemplate($('#foreach').html()).processTemplate(data);
$('#foreachResult').delegate('td', 'click', function() {
alert($(this).text());
});
});
</script>
</html>{#foreach $T.table as record begin=1}中如果把begin去掉的话会不显示数据怎么办呢?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>jTemplates</title>
</head>
<body>
<div id="result"></div>
<div id="foreachResult"></div>
</body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script src="http://jtemplates.tpython.com/jquery-jtemplates_uncompressed.js"></script><BR>
<BR><script type="text/template" id="foreach">
<table>
<thead>
<tr>
<td>Index</td>
<td>ID</td>
<td>Name</td>
<td>Age</td>
<td>Mail</td>
</tr>
</thread>
<tbody>
{#foreach $T.table as record begin=1}
<tr>
<td>{$T.record$index}</td>
<td>{$T.record.id}</td>
<td>{$T.record.name}</td>
<td>{$T.record.age}</td>
<td>{$T.record.mail}</td>
</tr>
{#/for}
</tbody>
</table>
</script>
<script>
$(function($) {
var data = {
name: 'User list',
list_id: 6,
table: [
{ id: 1, name: 'Alex', age: 21, mail: '[email protected]' },
{ id: 2, name: 'Amelie', age: 24, mail: '[email protected]' },
{ id: 3, name: 'Polly', age: 18, mail: '[email protected]' },
{ id: 4, name: 'Alice', age: 26, mail: '[email protected]' },
{ id: 5, name: 'Martha', age: 25, mail: '[email protected]' }
]
};
var mydata = { name: "Alex", age: "21" };
$("#result").setTemplate("My name is {$T.name}"); $("#result").processTemplate(mydata);
$('#foreachResult').setTemplate($('#foreach').html()).processTemplate(data);
$('#foreachResult').delegate('td', 'click', function() {
alert($(this).text());
});
});
</script>
</html>{#foreach $T.table as record begin=1}中如果把begin去掉的话会不显示数据怎么办呢?
你把 begin=1 改成 begin=3,就是从第三个开始