【问题标题】:Cannot set properties of null (setting 'onchange') I've got this error and I don't know what to do无法设置 null 的属性(设置 \'onchange\')我遇到了这个错误,我不知道该怎么办
【发布时间】:2022-11-05 10:26:38
【问题描述】:

我有这个错误,我不知道该怎么办

这是我的代码

js:

var uploadField = document.getElementById("file");

        console.log(uploadField);
        
            uploadField.onchange = function() {
                console.log("new")
                if(this.files[0].size > 2200000){
                        alert("File is too big!");
                        this.value = "";
            };
        };

html:

<input id ="post-input" id type="file" placeholder="Foto do Cartaz" name="image" accept=".png,.jpeg,.jpg,.gif" class="file-input" style="color: black;"/>

什么是最好的解决方案,我已经搜索过,但没有一个对每个人都有帮助的解决方案对我有帮助。

【问题讨论】:

  • 当我想要id="file" type="file" 时,你有id type="file"。您的语句失败,因为 uploadFieldnull

标签: javascript html notnull


【解决方案1】:

好像有错别字,需要改

  id ="post-input" id type="file"

   id ="post-input" type="file"

【讨论】:

    猜你喜欢
    • 2013-04-25
    • 1970-01-01
    • 2016-11-01
    • 2022-06-16
    • 1970-01-01
    • 1970-01-01
    • 2021-08-22
    • 2011-02-13
    • 2012-02-01
    相关资源
    最近更新 更多