使用jQuery剪辑内容 [英] Clip content with jQuery

查看:69
本文介绍了使用jQuery剪辑内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要获取跨度内的数字,请使用以下代码:

to just get the number inside span, use the code below:

<h3>test <span>inside 123458</span></h3>


alert($('h3 span').text().match(/\d/))
//123458

仅获取内容h3,而不占用内容范围,怎么办?

And to just get the content h3, without taking the span of content, how?

推荐答案

jQuery解决方案

jQuery solution

alert( $('h3').clone().find('span').remove().end().text() );

纯JS解决方案

alert( document.getElementsByTagName('h3')[0].childNodes[0].textContent );

示例: http://jsfiddle.net/2mTLg/1

这篇关于使用jQuery剪辑内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆