我有一个应用程序,它从输入字段中收集数据并将其附加到表中。请在下面查看我的代码。我究竟做错了什么?
function save(){
var name= $("#name").val();
var email= $("#email").val();
var telephone= $("#tel").val();
var street= $("#street").val();
var city= $("#city").val();
var state= $("#state").val();
var zip= $("#zip").val();
var inputArray = [name, email, telephone, street, city, state, zip];
var dataToStore = JSON.stringify(inputArray);
var uniqueID = ID();
sessionStorage.setItem(uniqueID, dataToStore);
display();
};
function display(){
var myArraySerialized = sessionStorage.getItem(uniqueID);
var myArray = JSON.parse( myArraySerialized );
var restoredName = myArray[0];
var restoredEmail = myArray[1];
var restoredTel = myArray[2];
var restoredStreet = myArray[3];
var restoredCity = myArray[4];
var restoredState = myArray[5];
var restoredZip = myArray[6];
//append filled information from the form to the table and 2 buttons - Update and Remove
$("#listContent table").append( "<tr>"+
"<td>" + restoredName + "</td>"+
"<td>" + restoredEmail + "</td>"+
"<td>" + restoredTel + "</td>"+
"<td>" + restoredStreet + "</td>"+
"<td>" + restoredCity + "</td>"+
"<td>" + restoredState + "</td>"+
"<td>" + restoredZip + "</td>"+
"<td>" + "<button>Update</button>" + "</td>" +
"<td>" + "<button>Remove</button>" + "</td>" +
"</tr>");
}
var ID = function () {
return '_' + Math.random().toString(36).substr(2, 9);
};
虽然控制台说没有定义 uniqueID,但我不明白为什么。当我使用任何其他变量时——姓名、电子邮件、街道等——它通过了,uniqueID——没有。我究竟做错了什么?感谢帮助