直接加入 append('p2') append('p1')
其实不需要换属性这么麻烦,你把两个div的id换一下不就行了么$('button').click(function(){ $("#p1").attr("id","p2");$("#p2").attr("id","p1");});