0

重複の可能性:
jQuery でテキスト文字列を区切る

私はすべての.postTag使用jqueryから1つの文字列を作成しました

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

JSFiddle:

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 に答える