通过模态上的jQuery将值注入html函数

时间:2017-07-28 02:09:32

标签: javascript jquery html laravel frontend

我有一个模态触发按钮,传递 id
在脚本部分,我需要将表单“注入”模态体 我的问题是传递脚本的html函数中的变量。怎么做?

HTML

<button value="{{ $etapaano->trabalho_id }}" id="{{ $etapaano->id }}" class="btn btn-primary btn-sm" title="Enviar Arquivo" data-toggle="modal" data-target="#myModalUploadArquivos"><i class="fa fa-upload"></i> Enviar</button> 

<div id="myModalUploadArquivos" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">Submeter Arquivo</h4>
            </div>
            <div id="modalBodyArquivo" class="modal-body">

            </div>   
        </div>
    </div>
</div>

脚本

$('#myModalUploadArquivos').on('show.bs.modal', function(e) {        
    var $modal = $(this);
    var etapaanoid = e.relatedTarget.id;
    var trabalhoid = e.relatedTarget.value;         

    $('#modalBodyArquivo').html('<form method="POST" enctype=multipart/form-data action="{{ url("arquivo/store/etapaanoid/trabalhoanoid") }}" file="true">{{ csrf_field() }}<label for="descricao">Arquivo *</label><input type="file" name="descricao" /></div><div class="modal-footer"><button type="button" class="btn btn-default" data-dismiss="modal">Fechar</button><button id="enviaArquivo" type="submit" class="btn btn-primary pull-right" title="Enviar Arquivo">Enviar</button></div></form>');
});

1 个答案:

答案 0 :(得分:0)

尝试替换它:

CopyTo

有了这个:

"{{ url("arquivo/store/etapaanoid/trabalhoanoid") }}"