How do you replace an HTML tag with another tag in jquery?(如何在 jquery 中用另一个标签替换 HTML 标签?)
问题描述
我有一个正在开发的网站,它使用aside"标签,无论我尝试什么,我都无法让 IE8 能够读取,即使使用 HTML5 Shiv 也是如此.所以,我想知道,你将如何使用 jQuery 将现有标签替换为其他标签?
例如,如果我想改变
<h3></h3></旁白>到
<h3></h3></div>那该怎么做?
 解决方案 试试这个:
$('aside').contents().unwrap().wrap('<div/>');
- 先获取
aside的内容. - 现在
解开内容. - 现在简单地说,
wrap 将内容放入一个新标签中,这里是 div. 
演示
<小时>此外,您可以使用 .replaceWith() 方法来执行此操作,例如:
$('aside').replaceWith(function () {返回 $('<div/>', {html: $(this).html()});});
演示
I have a site I'm working on and it uses 'aside' tags, which I'm not getting IE8 to be able to read no matter what I try, even with an HTML5 Shiv. So, I'm wondering, how would you replace existing tags with other tags with jQuery?
For example, if I wanted to change
<aside>
  <h3></h3>
</aside>
to
<div>
  <h3></h3>
</div>
How would that be done?
 解决方案 Try this:
$('aside').contents().unwrap().wrap('<div/>');
- Get the contents of 
aside first. 
- Now 
unwrap the contents. 
- Now simply, 
wrap the contents inside a new tag, here a div. 
DEMO
Also, you can do this using .replaceWith() method like:
$('aside').replaceWith(function () {
    return $('<div/>', {
        html: $(this).html()
    });
});
DEMO
                        这篇关于如何在 jquery 中用另一个标签替换 HTML 标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
	
本文标题为:如何在 jquery 中用另一个标签替换 HTML 标签?
				
        
 
            
        - CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
 - 失败的 Canvas 360 jquery 插件 2022-01-01
 - 400或500级别的HTTP响应 2022-01-01
 - Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
 - Flexslider 箭头未正确显示 2022-01-01
 - addEventListener 在 IE 11 中不起作用 2022-01-01
 - Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
 - 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
 - Fetch API 如何获取响应体? 2022-01-01
 - 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
 
						
						
						
						
						