我试图在网站上包含cloudinary的jquery小部件,以便客户端能够在上传之前裁剪图像。 (基本上是个人资料照片)。我已将以下代码添加到页面中:
$('#upload_widget_opener').cloudinary_upload_widget(
{ cloud_name: 'moin-qidwai-me', upload_preset: 'zn7qhrdi' ,'form':'#profile-setting',
'field_name':'userPhoto', 'thumbnails':'#user_photo', cropping: 'server', 'folder':
'user_photos' },
function(error, result) { console.log(error, result) });
我正在测试一些东西,因此我注释掉了这段代码,当我取消注释它时,它显然停止了工作并给了我这个错误:
Uncaught InvalidStateError: Failed to set the 'value' property on 'HTMLInputElement': This input element accepts a filename, which may only be programmatically set to the empty string.
通过撤消,我现在使整个文件处于与评论之前相同的状态,因此它不可能是我在评论之后所做的任何事情,但这就是它变得如此奇怪的原因。
另一个问题是,即使它正在工作,它也会添加隐藏类型的输入字段,有没有办法可以获取上传的图像的 url 并将我自己的输入字段的值设置为该 url?
最佳答案
这几天我也遇到了同样的错误。 我的代码片段:
<input id="fileDialog" type="file"/>
var chooser = document.querySelector('#fileDialog');
var choosed_file_path = "";
chooser.addEventListener("change", function(evt) {
//$("#fileDialog").val(this.value); // error
choosed_file_path = this.value;
}, false);
不允许设置“输入”的值。
关于jquery - Cloudinary 上传小部件与 "Failed to set the ' 上的 Jquery 'HTMLInputElement' value' 属性“,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27739383/