次の jQuery コードは、テキスト ボックスのグループ内のすべてのテキストを取得し<h2></h2>
、新しい<div>
.
コードは機能しますが、何らかの理由で<h2></h2>
最後に余分な空が追加されています。
したがって、たとえば、ページに 3 つのテキストボックスがある場合、それらの 3 つが表示されますが、次<h2></h2>
のように最後に空が追加されます。
<div id="desc1">
<h2>description 1</h2>
<h2>description 2</h2>
<h2>description 3</h2>
<h2></h2> <!--why is this here?-->
</div>
何が起こっているのかわかりません。誰でも提案できますか?
var newDiv = $("<div>").attr("id", 'desc' + counter);
var descriptions;
$(function () {
descriptions = $('textarea.descriptionTxt').map(function () {
return "<h2>" + this.value + "</h2>";
}).get();
$(newDiv ).html(answers.join(''));
});
$(newDiv).insertAfter(titleDiv).html();
ありがとう!