0

可能重复:
使用 jQuery 分隔文本字符串

我已经从所有.postTag使用 jquery中创建了一个字符串

sample:
    <span class='postTag'>Jquery</span>
    <span class='postTag'>php</span>
    <span class='postTag'>mysql</span>

输出 :

<input type='hidden' id='allInsertedTags' value='Jquery,php,mysql' />

谢谢你;D

4

4 回答 4

3

试试这个:

$("span.postTag").map(function() { return $(this).text(); }).get().join(", ");
于 2012-08-25T10:26:00.393 回答
1
var val = $('.postTag').map(function () { return $(this).text(); }).get().join(', ');​
$('#allInsertedTags').val(val);
于 2012-08-25T10:26:13.637 回答
1

JSF中:

strings = []
$.each($(".postTag"), function(k,v) {
   strings.push($(this).text())            
})
join = strings.join(",")
$("<input>").attr({
type: "hidden",
id: "allInsertedTags",
value: join
}).appendTo("body")    

​</p>

于 2012-08-25T10:27:13.900 回答
0

使用.text()来自 jQuery 的函数。

于 2012-08-25T10:26:32.803 回答