我使用jQuery获取div元素的内容,然后单击以下命令将该内容添加到文本区域:
$('.editBody').one('click', function() {
$(this).removeClass('two-columns');
$(this).removeClass('editBody');
var content = $(this).html();
var page = $(this).data('page');
var area = $(this).data('area');
$(this).html('<form name="editTagline" method="POST" action="editcontent.php">' +
'<input type="hidden" name="area" value="'+ area +'" />' +
'<input type="hidden" name="page" value="'+ page +'" />' +
'<textarea type="text" name="content" class="editBodytextarea">' + content + '</textarea>' +
'<button id="submit">Save</button></form>');
});但是,textfield包含<p>标记。我试过使用content.find("p").remove();,但是这只是中断,没有输出文本区域,只输出带有<p>标记的段落。有什么办法解决这个问题吗?
提前谢谢。
发布于 2014-03-17 16:09:55
var content = $(this).html();将返回原始的HTML
但是,var content = $(this).text();只会返回文本(减去标记)。试试看。
http://api.jquery.com/text/
https://stackoverflow.com/questions/22458964
复制相似问题