0

how to add this value to input name value to print values as input to help me with forms

$('<textarea/>').text(file.name).appendTo('#files');

< input type='text' name='photo[]' value=''/>

i need to get our as < input type='text' name='photo[]' value='file.jpg'/>

can any one help me with it that

full code

<script>
/*jslint unparam: true */
/*global window, $ */
$(function () {
    'use strict';
    // Change this to the location of your server-side upload handler:
    var url = (window.location.hostname === 'server/php/' ||
                window.location.hostname === 'server/php/') ?
                '//jquery-file-upload.appspot.com/' : 'server/php/';
    $('#fileupload').fileupload({
        url: url,
        dataType: 'json',
        done: function (e, data) {
            $.each(data.result.files, function (index, file) {
                $('<textarea/>').text(file.name).appendTo('#files');
            });
        },
        progressall: function (e, data) {
            var progress = parseInt(data.loaded / data.total * 100, 10);
            $('#progress .bar').css(
                'width',
                progress + '%'
            );
        }
    });
});
</script>
4

2 回答 2

1

不知何故我怀疑你想附加一个文本区域,所以用你想要附加的真实元素替换它()......并将它附加到表单......所以如果你的html看起来像这样......

<form id="files" action="" method="">
<textarea></textarea>
</form>

然后代码将是...

 done: function (e, data) {
        $.each(data.result.files, function (index, file) {
            $('<input type="text" name="photo[]" />').val(file.name).appendTo('#files');
        });
    },

或者试试这个...

 done: function (e, data) {
        $.each(data.result.files, function (index, file) {
            $('<input type="text" name="photo[]" value='+file.name+'/>').appendTo('#files');
        });
    },
于 2013-06-10T18:19:43.327 回答
0

use .val() instead of .text()

    done: function (e, data) {
        $.each(data.result.files, function (index, file) {
            $('<input type="text"/>').val(file.name).appendTo('#files');
        });
    },

EDIT: Proof of concept as jsFiddle: http://jsfiddle.net/b26tx/

于 2013-06-10T18:28:44.420 回答