我只想获取数字(123)而不是文本(确认),这是我的代码
<p>123confirm</p>
<script type="text/javascript">
$(document).ready(function(){
$('p').click(function(){
var sd=$(this).text();
alert(sd);
});
});
</script>
我认为 RegExp 是个好主意:
var sd = $(this).text().replace(/[^0-9]/gi, ''); // Replace everything that is not a number with nothing
var number = parseInt(sd, 10); // Always hand in the correct base since 010 != 10 in js
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)