![](/img/trans.png)
[英]html script tag not using type javascript <script type=“text/html”>?
[英]Add Javascript in <script type="text/html>…</script>
我是一個新程序員,我有一個小問題。 這是我的代碼的一部分:
<script type="text/html" id="experienceTmpl">
<li class="clearfix">
<div class="page-header no-border holder">
<a class="btn btn-icon-toggle btn-accent btn-delete stick-top-right"><span class="md md-delete"></span></a>
<h4 class="text-accent">Food Items
<%=index%>
</h4>
</div>
<div class="row">
<div class="col-md-4">
<div class="form-group">
<input type="text" class="form-control" id="experience-company-<%=index%>" placeholder="Food Item" name="experience-company-<%=index%>">
<label for="experience-company-<%=index%>"></label>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<input type="text" class="form-control" id="experience-functiontitle-<%=index%>" placeholder="Price" name="experience-functiontitle-<%=index%>" data-rule-number="true">
<label for="experience-functiontitle-<%=index%>"></label>
<p class="help-block">Digits only</p>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<select id="select1-<%=index%>" name="select1-<%=index%>" class="form-control" placeholder="Select" required>
<option value="Full Plate">Full Plate</option>
<option value="Half Plate">Half Plate</option>
<option value="Quarter Plate">Quarter Plate</option>
</select>
<label for="select1-<%=index%>"></label>
</div>
</div>
</div>
<div class="form-group">
<input type="text" multiple name="cuisine" class="tagsInput" value="Afghani,Mughlai" data-url="cuisine.json" data-user-option-allowed="true" data-load-once="true" required />
</div>
</li>
</script>
我的問題是如何在此html模板中添加此腳本,以便輸入標記中的類調用此腳本:
<script type="text/javascript">
$('.tagsInput').fastselect();
</script>
是否可以在html模板中調用此腳本,請提供我完全空白的解決方案。
我認為最好的方法是在渲染特定腳本/ html模板時將javascript動態添加到DOM。
詳細信息:在應用程序級別,您知道要在頁面中創建哪個模板。 為每個模板ID制作單獨的JS文件,並將與模板相關的活動javascript文件注入DOM。
注意:這就像您要創建模板引擎一樣。 使用現有模板引擎(例如Handlebars,JADE,Underscore)的最佳方法。 它將節省您的開發時間並減少錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.