"< div class =" text"数据名称=" TEST1"> < / DIV>"
< div class =" text"数据名称=" TEST1"> < / DIV>
< div class =" text"数据名称=" TEST1"> < / DIV>
< div class =" text"数据名称=" TEST1"> < / DIV>
< div class =" text"数据名称=" TEST1"> < / DIV>
追加应该是这样的
< div class =" text"> < p> test 1< / p>< / div>
< div class =" text"> < p> test 2< / p>< / div>
答案 0 :(得分:2)
像这样:
$('div.text').each(function() {
var $this = $(this);
$this.append($('<p>').html($this.data('name')));
});
答案 1 :(得分:0)
转换元素的一种方法。
$('div[data-name]').each(function() {
var data = $(this).data("name");
$(this).removeAttr( "data-name" );
data = data.slice(0, 4) + " " + data.slice(4);
$(this).append("<p>" + data);
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="text" data-name="test1"> </div>
<div class="text" data-name="test1"> </div>
<div class="text" data-name="test1"> </div>
<div class="text" data-name="test1"> </div>
<div class="text" data-name="test1"> </div>