iframe upload

html:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<form method='POST' enctype='multipart/form-data' target='upload_iframe' class='common-note-form new_note' accept-charset="UTF-8" action='http://localhost/boss/profile/issue/js/upload_file";'>
<textarea id='comment' name='comment' class='note_text form-control' rows='5'></textarea>
<div class="note-form-actions">
<div class="buttons">
<input type="hidden" value="15" name='issue_id'>
<input id='submitcom' class='btn btn-primary comment-btn btn-grouped js-comment-button' type='submit' value='发表评论'>
</div>
<div class="note-form-option pull-left">
<a class="choose-btn btn js-choose-note-attachment-button btn-default">

<span>选择文件...</span>
</a>
&nbsp;<span class="file_name js-attachment-filename">文件名</span>
<input class="js-note-attachment-input hidden" id="note_attachment" name="files[note]" type="file">
</div>
</div>
</form>
<iframe name='upload_iframe' class='hide'></iframe>

####js:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// 点击上传文件按钮,触发input file空间
$('.choose-btn').on('click', function() {
var target;
return target = $(this).closest('form'),
target.find('.js-note-attachment-input').click();
});
// file空间变化事件
$('.js-note-attachment-input').on('change', function() {
var ele = $(this).closest('form');
var file_name = $(this).val().replace(/^.*[\\\/]/, "");
ele.find('.js-attachment-filename').text(file_name);
return false;
});
//发表评论
$('#submitcom').on('click', function() {
$(this).closest('form').submit();
var comment = $('#comment').val();
if(!comment.length) {
$.show_message('评论内容不能为空!');
return false;
} else {
$(this).closet('form').submit();
}
return false;
});