javascript代码不使用x-tmpl或x-jQuery-tmpl模板运行

javascript代码不使用x-tmpl或x-jQuery-tmpl模板运行,javascript,jquery,jquery-plugins,yii-extensions,yii-xupload,Javascript,Jquery,Jquery Plugins,Yii Extensions,Yii Xupload,我有(xupload)blueimp插件的模板: <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>

我有(xupload)blueimp插件的模板:

<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>

{%for(var i=0,file;file=o.files[i];i++){%}
标题:
{%=文件名%}
{%=o.formatFileSize(file.size)%}
{%if(file.error){%}
错误{%=file.Error%}
{%}如果(o.files.valid&&!i){%}
{%if(!o.options.autoUpload){%}
开始
{% } %}
{%}其他{%}
{% } %}
{%if(!i){%}
取消
{% } %}
{% } %}
我试图运行这个javascript代码,但它不起作用,但当我在控制台内为firbug运行它的工作时,当页面加载完成时,如何使它运行

<script type="text/javascript">
jQuery(document).ready(function(){
    $("input[type=text]").focus(function(){
        alert('some text');
    });
});
</script>

jQuery(文档).ready(函数(){
$(“输入[type=text]”)。焦点(函数(){
警报(“某些文本”);
});
});
就我而言, 我正在使用yii扩展(选择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>

{%for(var i=0,file;file=o.files[i];i++){%}
{%if(file.error){%}
错误{%=file.Error%}
{%}如果(o.files.valid&&!i){%}
{%if(!o.options.autoUpload){%}
开始
{% } %}
{%}其他{%}
{% } %}
{%if(!i){%}
取消
{% } %}
{% } %}

很抱歉,异步问题的级别很高

MVC 有两个封装的MVC(正常情况下)

  • 主要是DB(模型)、HTML(视图)、PHP(控制器)-服务器端
  • 其次是JSON/AJAX(模型)、模板(视图)、JavaScript(控制器)-客户端
  • 第一个MVC还可以,第二个是坏习惯

  • 您可以在辅助视图静态中从主MVC调用模型,而不是通过辅助控制器(Javascript)将模型从主MVC引导到辅助视图
  • 警报(“某些文本”);绑定到所有可见的输入字段(模板中的输入未附加)。请理解,此代码不会触发“警报”以输入稍后呈现的文本
  • 通常,将主PHP与辅助模板分离会成功,因此您必须将信息通过主控制器、主视图、辅助模型、辅助控制器引导到辅助视图


    我知道这是一个很大的工作,但唯一的清理方法。

    你是在添加页面吗?我试着在模板前后添加javascript,仍然一样,当我使用firebug控制台运行它时,它的工作是指您的输入是动态生成的吗???是的,它的动态生成在显示动态生成的输入后调用该函数。。你能把输入的附加部分贴在这里吗