English 中文(简体)
如何在不使用分类数据的情况下消除标记?
原标题:How do we remove the span tag without lossing data using jquery?
  • 时间:2011-08-24 10:36:18
  •  标签:
  • jquery
  • html

我的结构如下:

    <ul class="sub-menu">
    <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-34" id="menu-item-34"><a href="http://localhost/artofsujata/testimonials/">
<span class="menu_left">&nbsp;</span> 
<span class="menu_center">Testimonials</span> 
<span class="menu_right">&nbsp;</span>
</a>
</li>   
</ul>

i 需要在不丢失数据的情况下拆除标签,并且需要超出下文所述的固定装置。

    <ul class="sub-menu">
    <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-34" id="menu-item-34"><a href="http://localhost/artofsujata/testimonials/">
&nbsp; 
Testimonials
&nbsp;
</a>
</li>   
</ul>

如何利用 j?

最佳回答

这样做是为了:

$( ul li a ).html($( ul li a ).text());

<代码>$(ul li a ).text(>, 您在标签上选择了所有案文节点。 和$(ul li a .html() ,请将所有选定的案文节点列入阁下的标签。 这导致从那里 all掉所有tag。

对多个低收入国家来说,你可以这样做:

$( ul.sub-menu > li.menu-item > a ).each(function(){
  $(this).html($(this).text());
});
问题回答

正如在

$("span").contents().unwrap();

Fiddle here

显然,你可能希望在你的菜单上更精确地把这一目标作为目标,以避免在网页上删除其他时间:

$(".sub-menu li span").contents().unwrap();

另一方面,我建议,根据你的实际问题,改变安全局的风格可能比较容易。

阅读所有标签,将数据储存在联合材料的一个阵列中,删除所有标签,然后用你需要的格式重新公布数据?





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签