简体   繁体   English

jQuery如何在第一个元素之前删除逗号?

[英]jQuery how to remove the comma before first element?

I am getting an array using jQuery push().But the there is a comma before first element.I need the array without comma for the first element(Need comma for rest of the elements).Any Idea? 我使用jQuery push()得到一个数组。但是在第一个元素之前有一个逗号。我需要第一个元素没有逗号的数组(其余元素需要逗号)。任何想法?

Thanks 谢谢

function delImg(newThis){
    $(newThis).parent().hide();
    var Id = $(newThis).siblings('.hidden').html();
    Ids.push(Id);
    alert(Ids);
    return Ids;

}

You are adding a empty element to array so you get , at starting 要添加空元素阵列等你拿,在开始

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;
}

function delImg(newThis) {
    $(newThis).parent().hide();
    var Id = $(newThis).siblings('.hidden').html().trim();
    if (Id !== '') {
        Ids.push(Id);
    }
    alert(Ids);
    return Ids;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM