3
運行我有這個模板(xupload)blueimp插件:JavaScript代碼不與X-TMPL或x jQuery的TMPL模板
<script id="template-upload" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
<tr class="template-upload fade">
<td class="preview"><span class="fade"></span></td>
<td class="title"><label>Title: <input type="text" name="title" required></label></td>
<td class="name"><span>{%=file.name%}</span></td>
<td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td>
{% if (file.error) { %}
<td class="error" colspan="2"><span class="label label-important">Error</span> {%=file.error%}</td>
{% } else if (o.files.valid && !i) { %}
<td>
<div class="progress progress-success progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"><div class="bar" style="width:0%;"></div></div>
</td>
<td class="start">{% if (!o.options.autoUpload) { %}
<button class="btn btn-primary">
<i class="icon-upload icon-white"></i>
<span>Start</span>
</button>
{% } %}</td>
{% } else { %}
<td colspan="2"></td>
{% } %}
<td class="cancel">{% if (!i) { %}
<button class="btn btn-warning">
<i class="icon-ban-circle icon-white"></i>
<span>Cancel</span>
</button>
{% } %}</td>
</tr>
{% } %}
</script>
我試圖運行這段JavaScript代碼,它不工作,但是當我裏面控制檯運行它firbug的工作,是什麼使它運行時,頁面加載完成
<script type="text/javascript">
jQuery(document).ready(function(){
$("input[type=text]").focus(function(){
alert('some text');
});
});
</script>
在我的情況下, 我使用警予擴展(選擇2)該擴展生成JavaScript選擇方式:
<script id="template-upload" type="text/x-jQuery-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
<tr class="template-upload fade">
<td class="preview">
<span class="fade"></span>
</td>
{% if (file.error) { %}
<td class="error" colspan="2"><span class="label label-important">Error</span> {%=file.error%}</td>
{% } else if (o.files.valid && !i) { %}
<td>
<label><?php echo CHtml::label('Keywords', 'keywords'); ?></label>
<?php
echo CHtml::textField('tags',$selected,array('id'=>'tags'));
$this->widget('ext.select2.ESelect2',array(
'selector'=>'#tags',
'options'=>array(
'tags'=>$tags,
'width'=>'400px;',
),
));
?>
</td>
<td>
<div class="progress progress-success progress-striped active"><div class="bar" style="width:0%;"></div></div>
</td>
<td class="start">{% if (!o.options.autoUpload) { %}
<button class="btn btn-primary">
<i class="icon-upload icon-white"></i>
<span>Start</span>
</button>
{% } %}</td>
{% } else { %}
<td colspan="2"></td>
{% } %}
<td class="cancel">{% if (!i) { %}
<button class="btn btn-warning">
<i class="icon-ban-circle icon-white"></i>
<span>Cancel</span>
</button>
{% } %}</td>
</tr>
{% } %}
</script>
您是否正在追加頁面? – bipen 2013-03-12 07:59:36
我試着把這個JavaScript之前和之後的模板,仍然相同,其工作時,我運行它使用螢火蟲控制檯 – user1942792 2013-03-12 08:11:02
我的意思是你的輸入動態生成? – bipen 2013-03-12 08:12:52