我只是想问一下jQuery
。 jQuery
可以做到这一点:
<h1 id="lorem-ipsum">Hello World!</h1>
对此:
<div id="lorem-ipsum"></div>
<h1>Hello World!</h1>
最佳答案
你的意思是像这个人:工作演示位动态版本:http://jsfiddle.net/QSdqM/ 或 http://jsfiddle.net/GQzFU/
希望它能帮助解决问题:)
API:http://api.jquery.com/replaceWith/
代码
$('h1').replaceWith(function() {
return '<div id="' + this.id + '"></div><h1>' + $(this).text() + '</h1>'
});
或
$('h1').replaceWith('<div id="lorem-ipsum"></div><h1>Hello World!</h1>');
alert($('body').html());
关于javascript - 具有相同 id 的 jQuery .before,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11606491/