我正在使用 jQuery Push() 获取一个数组。但第一个元素之前有一个逗号。我需要第一个元素不带逗号的数组(但其余元素需要逗号)。有什么想法吗?
function delImg(newThis){
$(newThis).parent().hide();
var Id = $(newThis).siblings('.hidden').html();
Ids.push(Id);
alert(Ids);
return Ids;
}
最佳答案
您正在向数组添加一个空元素,以便在开始时得到 ,
function delImg(newThis) {
$(newThis).parent().hide();
var Id = $(newThis).siblings('.hidden').html();
if ($.trim(id) !== '') { //push to array if id value is not empty
Ids.push(Id);
}
alert(Ids);
return Ids;
}
<小时/>
关于javascript - jQuery 如何删除第一个元素之前的逗号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20073248/