m0_71681226 2022-10-24 22:53 采纳率: 100%
浏览 41
已结题

js数组存储数据,在html添加数据时undefined

js数组存储数据,在html添加数据时undefined

数组:


```javascript
var list = [{ "Id": '0', "FirstName": "Stark", "LastName": "Bill", "DateOfBirth": "2000/10/11", "Gender": "Male", "PrimaryInsurance": "Medicare", "Address": "ddadsdasd", "ContactNumber": "1338872818738", "NextOfKin": "weqe" },
    { "Id": '1', "FirstName": "Shown", "LastName": "Jenny", "DateOfBirth": "2000/10/11", "Gender": "Male", "PrimaryInsurance": "Medicare", "Address": "ddadsdasd", "ContactNumber": "1338872818738", "NextOfKin": "weqe" },
    { "Id": '2', "FirstName": "Geogrge", "LastName": "Hash", "DateOfBirth": "2000/10/11", "Gender": "Male", "PrimaryInsurance": "Medicare", "Address": "ddadsdasd", "ContactNumber": "1338872818738", "NextOfKin": "weqe" },
    { "Id": '3', "FirstName": "Intwre", "LastName": "zaiwoo", "DateOfBirth": "2000/10/11", "Gender": "Male", "PrimaryInsurance": "Medicare", "Address": "ddadsdasd", "ContactNumber": "1338872818738", "NextOfKin": "weqe" },
    { "Id": '4', "FirstName": "Niko", "LastName": "baby", "DateOfBirth": "2000/10/11", "Gender": "Male", "PrimaryInsurance": "Medicare", "Address": "ddadsdasd", "ContactNumber": "1338872818738", "NextOfKin": "weqe" }];

html:

Add a new patient
Patient ID*:<input type="text" id="newId" value="">
First name*:<input type="text" id="newFirstName" value="">
Last name*:<input type="text" id="newLastName" value="">
Date of birth *:<input type="text" id="newDateOfBirth" value="">
Gender*:<input type="text" id="newGender" value="">
Primary insurance*:<input type="text" id="newPrimaryInsurance" value="">
Address *:<input type="text" id="newAddress" value="">
Contact number *:<input type="text" id="newContactNumber" value="">
Next of kin:<input type="text" id="newNextOfKin" value="">
<input type="button" value="Add a new Patient" onclick="addNewPatient();">

Javascript:

function addNewPatient(){
    
     var newId=document.getElementById("newId");
     var newFirstName=document.getElementById("newFirstName");
     var newLastName=document.getElementById("newLastName");
     var newDateOfBirth=document.getElementById("newDateOfBirth");
     var newGender=document.getElementById("newGender");
     var newPrimaryInsurance=document.getElementById("newPrimaryInsurance");
     var newAddress=document.getElementById("newAddress");
     var newContactNumber=document.getElementById("newContactNumber");
     var newNextOfKin=document.getElementById("newNextOfKin");
     
     var newPatient=new Array(newId.value,newFirstName.value,newLastName.value,newDateOfBirth.value,newGender.value,newPrimaryInsurance.value,newAddress.value,newContactNumber.value,newNextOfKin.value);
     list.push(newPatient);
     
     refreshList();
}

错误:

img

请问改怎么解决这个问题

  • 写回答

2条回答 默认 最新

  • CSDN专家-showbo 2022-10-24 23:01
    关注

    显示的时候用的json对象,加入到list集合中也要json对象才行

    
            function addNewPatient() {
    
                var newId = document.getElementById("newId");
                var newFirstName = document.getElementById("newFirstName");
                var newLastName = document.getElementById("newLastName");
                var newDateOfBirth = document.getElementById("newDateOfBirth");
                var newGender = document.getElementById("newGender");
                var newPrimaryInsurance = document.getElementById("newPrimaryInsurance");
                var newAddress = document.getElementById("newAddress");
                var newContactNumber = document.getElementById("newContactNumber");
                var newNextOfKin = document.getElementById("newNextOfKin");
    
                var newPatient = {
                    Id: newId.value,
                    FirstName: newFirstName.value,
                    LastName: newLastName.value,
                    DateOfBirth: newDateOfBirth.value,
                    Gender: newGender.value,
                    PrimaryInsurance: newPrimaryInsurance.value,
                    Address: newAddress.value,
                    ContactNumber: newContactNumber.value,
                    NextOfKin: newNextOfKin.value
                }; 
                list.push(newPatient);
    
                refreshList();
            }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 10月24日
  • 已采纳回答 10月24日
  • 创建了问题 10月24日

悬赏问题

  • ¥15 编写vba代码实现数据录入工作
  • ¥15 做过TCL海信电视小米电视相关影视会员软件私我
  • ¥15 Mapreduce是正常的,在运行其他jar包时并没有任何问题,只是在做LogCount.jar 时出的问题。如图所示
  • ¥15 ImportError: DLL load failed while importing _iterative: 找不到指定的模块。
  • ¥15 如何通过交互分析得出某高危患者对放疗获益更多
  • ¥15 相关性分析中,p<0.05, r=0.29,怎么评价相关性呢
  • ¥15 docker部署Mongodb后输入命令报错?
  • ¥15 将下列流程图转变成python程序代码
  • ¥15 我需要全国每个城市的最新小区名字等数据。
  • ¥15 开发一个小区生态的小程序