Javascript 如何解决;未捕获类型错误:无法读取属性';价值';“无效”的定义;

Javascript 如何解决;未捕获类型错误:无法读取属性';价值';“无效”的定义;,javascript,asp.net,Javascript,Asp.net,我在ASP.NET中制作了我的第一份注册表格,并且使用了一些Javascript我在注册时出现了以下错误 未捕获的TypeError:无法读取null的属性“值” 以下是我的javascript代码: function f_submitForm() { $("#submit").css("display", "none"); $("#load").css("display", "block"); const auxPriorityInput = document.ge

我在ASP.NET中制作了我的第一份注册表格,并且使用了一些Javascript我在注册时出现了以下错误

未捕获的TypeError:无法读取null的属性“值”

以下是我的javascript代码:

function f_submitForm() {
    $("#submit").css("display", "none");
    $("#load").css("display", "block");


    const auxPriorityInput = document.getElementById("ticketPriorityInput");
    const auxticketService = document.getElementById("ticketServiceInput");
    const auxticketSubService = document.getElementById("ticketSubServiceInput");
    const auxCategoryInput = document.getElementById("ticketCategoryInput");
    const auxticketOrigin = document.getElementById("ticketOriginInput");

    const form = new FormData();

    const ins = document.getElementById("file").files.length;
    for (let x = 0; x < ins; x++) {
        form.append("files[]", document.getElementById("file").files[x]);
    }

    form.append("ticketIdAppliInput", document.getElementById("ticketIdAppliInput").value);
    form.append("ticketNameAppliInput", document.getElementById("ticketNameAppliInput").value);
    form.append("ticketEmailAppliInput", document.getElementById("ticketEmailAppliInput").value);    
    form.append("ticketExtAppliInput", document.getElementById("ticketExtAppliInput").value);
    form.append("ticketPhoneAppliInput", document.getElementById("ticketPhoneAppliInput").value);
    form.append("ticketAreaAppliInput", document.getElementById("ticketAreaAppliInput").value);
    form.append("ticketLocationAppliInput", document.getElementById("ticketLocationAppliInput").value);
    form.append("ticketSubjectInput", document.getElementById("ticketSubjectInput").value);
    form.append("ticketDescrInput", document.getElementById("ticketDescrInput").value);
    form.append("ticketPriorityInput", auxPriorityInput.options[auxPriorityInput.selectedIndex].value);
    form.append("ticketServiceInput", auxticketService.options[auxticketService.selectedIndex].value);
    form.append("ticketSubServiceInput", auxticketSubService.options[auxticketSubService.selectedIndex].value);
    form.append("ticketCategoryInput", auxCategoryInput.options[auxCategoryInput.selectedIndex].value);
    form.append("ticketOriginInput", auxticketOrigin.options[auxticketOrigin.selectedIndex].value);

扩展:

首先,请发布您的HTML。没有它,很难说发生了什么


但错误是相当直接的。在HTML中似乎没有包含
id=“ticketExtAppliInput”
的元素。检查拼写是否有误或为什么会丢失。这是
getElementById
返回
null

的最可能原因,该错误表明javascript找不到id为“ticketTextAppliInput”的元素。第一步是检查HTML并确保该元素的id拼写正确


更普遍的问题是,您在DOM中搜索元素,然后尝试访问它们的“value”属性。最佳做法是,在假设您可以获得该元素的值之前,确保您确实找到了该元素。

在反复研究之后,我找到了验证问题的解决方案,并按照以下方式进行了验证,如果该元素为空,请尝试进行验证。请分配值0

function f_submitForm() {
$("#submit").css("display", "none");
$("#load").css("display", "block");

const auxPriorityInput = document.getElementById("ticketPriorityInput");
const auxticketService = document.getElementById("ticketServiceInput");
const auxticketSubService = document.getElementById("ticketSubServiceInput");
const auxCategoryInput = document.getElementById("ticketCategoryInput");
const auxticketOrigin = document.getElementById("ticketOriginInput");


const form = new FormData();

const ins = document.getElementById("file").files.length;
for (let x = 0; x < ins; x++) {
    form.append("files[]", document.getElementById("file").files[x]);
}

form.append("ticketIdAppliInput", document.getElementById("ticketIdAppliInput").value);
form.append("ticketNameAppliInput", document.getElementById("ticketNameAppliInput").value);
form.append("ticketEmailAppliInput", document.getElementById("ticketEmailAppliInput").value);    
if ($('ticketExtAppliInput').val() == "") {

    //we give it the value of zero by not having any value
    document.getElementById("ticketExtAppliInput").value = "0";
} 
form.append("ticketPhoneAppliInput", document.getElementById("ticketPhoneAppliInput").value);
form.append("ticketAreaAppliInput", document.getElementById("ticketAreaAppliInput").value);
form.append("ticketLocationAppliInput", document.getElementById("ticketLocationAppliInput").value);
form.append("ticketSubjectInput", document.getElementById("ticketSubjectInput").value);
form.append("ticketDescrInput", document.getElementById("ticketDescrInput").value);
form.append("ticketPriorityInput", auxPriorityInput.options[auxPriorityInput.selectedIndex].value);
form.append("ticketServiceInput", auxticketService.options[auxticketService.selectedIndex].value);
form.append("ticketSubServiceInput", auxticketSubService.options[auxticketSubService.selectedIndex].value);
form.append("ticketCategoryInput", auxCategoryInput.options[auxCategoryInput.selectedIndex].value);
form.append("ticketOriginInput", auxticketOrigin.options[auxticketOrigin.selectedIndex].value);
函数f_submitForm(){ $(“#提交”).css(“显示”、“无”); $(“#加载”).css(“显示”、“块”); const auxPriorityInput=document.getElementById(“ticketprioritynput”); const auxticketService=document.getElementById(“ticketServiceInput”); const auxticketSubService=document.getElementById(“ticketSubServiceInput”); const auxCategoryInput=document.getElementById(“ticketCategoryInput”); const auxticketOrigin=document.getElementById(“ticketOriginInput”); const form=new FormData(); const ins=document.getElementById(“文件”).files.length; for(设x=0;x无法获取函数参数的
属性。以下是可从中获取值的快速列表。请检查HTML元素
“ticketTextAppliInput”
existsCheck在运行时检查浏览器开发工具。是否可能在调用之前删除、隐藏或重命名了此元素?浏览器说它不存在