我想获取 li 元素的 ID 属性值(它将是一个 userID),并将其作为字符串的一部分,最终我将用这个字符串作为变量名的一部分。我将使用这个变量名创建一个数组。
我理解基础知识,但好像找不到正确的 jQuery/javascript 组合来实现这个魔法。
我理解基础知识,但好像找不到正确的 jQuery/javascript 组合来实现这个魔法。
jQuery('#user-list li').click(function() {
var userID = jQuery(this).attr("id");
// i want to add the word array to the end of userID
var theVariableName = userID + "Array";
// I want to use this variable to create an array
var theVariableName = new Array();
// I want to continue to use the name throughout my document
theVariableName.push({startTime: 7, endTime: 10});
alert(theVariableName[0].startTime);
});
var theVariableName
的值会被重写。 - Dmitry Koroliov