开发者

Make space or special character between fetched contents

Thanks for helping to solve a problem at: .val() and .text() don't work?

Now I have a new question, look at my problem in: http://jsfiddle.net/arlopa/B5aTC/

When you click on "submit", this appears in the textarea:

**content 1acontent 2a**

If I emai开发者_如何转开发l this text, the user can't read it!

I want to fix it so that it's formatted like:

(content 1a) ( content 2a )

OR

content 1a

content 2a

OR

content 1a | content 2a

Thanks.


Your JQuery selector is causing the formatting issue. What you can do is get a collection of the elements and then iterate over them using .each() to build up the way you want to display them.

Here is your javascript with the items updated to display with a pipe, and with your original total code:

$('#shopform').submit(function() {
    var items = '';
    var tprice = $('.simpleCart_total').text();

$.each($('.simpleCart_items'), function(index, value) { 
    items = index === 0 ? value.textContent : items + ' | ' + value.textContent;
});

    $('#itemsinfo').val(items);
    $('#totalprice').val(tprice);
    return false;
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜