添加JavaScript在<脚本类型=“text/html的> ...
问题描述:
我是一个新的程序员,我有一个小问题,这是我的代码的一部分:添加JavaScript在<脚本类型=“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模板,请提供解决方案,我完全空白
。
答
I th油墨最好的方式是在渲染特定的脚本/ html模板时动态地将javascript添加到DOM。
详细信息: 在应用程序级别,您知道哪个模板将在页面中呈现。为每个模板ID创建单独的JS文件,并将活动模板相关的JavaScript文件注入DOM。
注意: 这就像你要创建模板引擎。使用现有模板引擎(如Handlebars,JADE,Underscore)的最佳方法。它会节省您的开发时间并减少错误。
嗨,尝试写在HTML和PHP,不要使用模板和框架,如果你新和总空白。赚取第一个PHP,HTML,CSS,MySQL,然后尝试写模板或使用框架(不要浪费你的时间)。 – 2017-02-26 14:15:28