亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

我可以使用 val() 插入或編輯文件輸入嗎?

我可以使用 val() 插入或編輯文件輸入嗎?

慕娘9325324 2022-06-16 10:36:14
我正在使用 jQuery 為管理面板制作 CRUD。我正在使用以下表格將“視頻”添加到列表中:因此,當我提交表單時,所有字段都被推送到一個名為videos的數組中,并且表單被清除。當我嘗試編輯特定視頻并嘗試將當前視頻的所有值插入表單的字段時,問題就開始了。我正在這樣做:$('#video-title').val(video.videoTitle);$('#video-segment').val(video.videoSegment);$('#video-thumbnail').val(video.videoThumbnail);$('#datepicker3').val(video.videoDate);$('#video-description').val(video.videoDescription);$('#bright-id').val(video.videoBrightCoveId);一切正常,但在視頻縮略圖(為該特定視頻上傳的圖像)給我這個錯誤:jquery.min.js:2 Uncaught DOMException: Failed to set the 'value' property on 'HTMLInputElement': This input element accepts a filename, which may only be programmatically set to the empty string.    at HTMLInputElement.<anonymous> (https://localhost:5001/lib/jquery/jquery.min.js:2:68568)    at Function.each (https://localhost:5001/lib/jquery/jquery.min.js:2:2777)    at k.fn.init.each (https://localhost:5001/lib/jquery/jquery.min.js:2:1419)    at k.fn.init.val (https://localhost:5001/lib/jquery/jquery.min.js:2:68263)    at HTMLButtonElement.<anonymous> (https://localhost:5001/admin/events/create:1239:35)    at HTMLTableSectionElement.dispatch (https://localhost:5001/lib/jquery/jquery.min.js:2:42571)    at HTMLTableSectionElement.v.handle (https://localhost:5001/lib/jquery/jquery.min.js:2:40572)我的問題是:有一種方法可以編輯縮略圖字段嗎?還是我這樣做的方式不可能?.
查看完整描述

1 回答

?
慕容708150

TA貢獻1831條經驗 獲得超4個贊

您可以使用DataTransfer()設置輸入類型文件的值。


例如:


var tst =   new DataTransfer(); 

tst.items.add(new File(['test'], video.videoThumbnail));

video_thumbnail.files = tst.files;

var tst =   new DataTransfer(); 

tst.items.add(new File(['test'], 'yourimage.jpg'));

video_thumbnail.files = tst.files;

 <input type="file"  id='video_thumbnail'>


查看完整回答
反對 回復 2022-06-16
  • 1 回答
  • 0 關注
  • 127 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號