我正在使用html模板:
<script id="locationTemplate" type="application/template" >
<p>
<input id="searchText" type="text" />
<input id="searchlocation" type="submit" value="Search" />
</p>
<p>
<label>Location Name</label>
<input id="locationName" type="text" />
</p>
<div id="map"></div>
</script>
Run Code Online (Sandbox Code Playgroud)
我可以加载模板,但是当我尝试在模板中找到控件时,我不能.
this.template = $('#locationTemplate');
this.searchText = $(this.template.html()).find('input#searchText');
this.locationName = this.template.find('p input#locationName');
Run Code Online (Sandbox Code Playgroud)
我在这里错过了什么?我尝试了两种不同的方法.
更新:
我有这个代码工作:
this.template = $('#locationTemplate');
this.searchText = $(this.template.html()).find('input#searchText');
this.locationName = $(this.template.html()).find('input#locationName');
Run Code Online (Sandbox Code Playgroud)
但我很困惑为什么我必须将html转储到另一个jQuery实例.为什么我不能只使用template.find方法,因为模板已经包装在jQuery中...
| 归档时间: |
|
| 查看次数: |
1154 次 |
| 最近记录: |