jquery tmpl

1.定义模板(在静态页面中定义,也可在js中定义)
<ul class='ulCon'>
	<li class='s125 f12' qId='{{= id}}'>{{= id}}</li>
	<li class='one f12 questionName' title='{{= title}}' qTitle='{{= title}}'>
		<a href='javascript:viewWindow({{= id}});' method='previewQuestion()'>{{= title}}</a>
	</li>
	<li class='s145 f12' qQuesType='{{ = quesType}}'>{{= quesTypeStr}}</li>
	<li class='s125 f12' qUpdateTime='{{= updateTime}}'>{{= updateTimeStr}}</li>
	<li class='six'>
		{{if getNodeType()==3}}
			<a href='javascript:;' method='delAbsoluteQuestion'>彻底删除</a>
			<a href='javascript:;' method='recoverQuestion'>恢复</a>
		{{else getNodeType()==2}}
			<a href='javascript:addWindow({{= id}})'  >修改</a>
			<a href='javascript:;' method='delQuestion'>删除</a>
			<a href='javascript:;' method='mvQuestion'>移至</a></li>
		{{else}}
			<a href='javascript:addWindow({{= id}})' >修改</a>
			<a href='javascript:;' method='delQuestion'>删除</a>
		{{/if}}
	<div class='clear'></div>
</ul>
</script>


2.数据渲染模板,用选择器插入
$("#questionListTmpl").tmpl(questionList).insertAfter(".ulTit");


3.目标位置
				<div>
					<ul class="ulTit">
						<li class="s125">题目编号</li>
						<li class="one">题目名称</li>
						<li class="s145">题目类型</li>
						<li class="s125">创建时间</li>
						<li class="six">操作</li>
					</ul>
				</div>


4.五种插入方式
appendTo: "append",
prependTo: "prepend",
insertBefore: "before",
insertAfter: "after",
replaceAll: "replaceWith"

你可能感兴趣的:(JavaScript)