如何将此值添加到输入名称值以打印值作为输入以帮助我使用表单
$('<textarea/>').text(file.name).appendTo('#files');
&LT; input type ='text'name ='photo []'value =''/&gt;
我需要得到我们的&lt; input type ='text'name ='photo []'value ='file.jpg'/&gt;
任何人都可以帮助我
完整代码
<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>
答案 0 :(得分:1)
不知怎的,我怀疑你想要附加一个textarea,所以用你要追加的真实元素替换它()...并将它附加到formm ... 所以如果你的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');
});
},
答案 1 :(得分:0)
使用.val()代替.text()
done: function (e, data) {
$.each(data.result.files, function (index, file) {
$('<input type="text"/>').val(file.name).appendTo('#files');
});
},
编辑:概念证明为jsFiddle:http://jsfiddle.net/b26tx/