0

I have the following code;

var pro = $(".pro").map(function() {
    return this.innerHTML + '(';
}).get();
var qty = $(".qty").map(function() {
    return this.value + ')\xa0';
}).get();
var total = pro + qty;

When I print total, it prints as PRODa(,PRODb(2) ,1). I'm trying to show it as PRODa(2) PRODb(2). Basically to put them in order, pro with the associated qty. Is this possible to do within the code above and not under some type of echo/print?

4

1 回答 1

2

尝试这样的事情:

var total = $(".pro,.qty").map(function() {
    if($(this).hasClass('pro'))    
        return this.innerHTML + '(';
    else
        return this.value + ')\xa0';
}).get();

alert(total);

希望我理解正确。我没有测试因为我不知道你使用的结构但是应该适用于交替.pro.qty

于 2013-06-26T19:46:32.037 回答