jq获取字符串中的数字 jq如何获取id里的数字

我的每个id为 id1、id2、id3….

每次我需要拿到id后面跟的数字

<!-- 简单写几个按钮 -->
<div class="btn-box">
	<button id="btn1">按钮1</button>
	<button id="btn2">按钮2</button>
	<button id="btn3">按钮3</button>
</div>
<script>
	// 当点击时,我要拿到对应id后面拼接的数字来判别执行的事件
	$(".btn-box button").click(function(){
		var IdKey = $(this).attr('id').replace(/[^0-9]/ig,"");
		console.log(IdKey);
	})
</script>
转载请注明来源:陌涛小站/文章链接:
正文到此结束

评论区 0

发表评论

This site uses Akismet to reduce spam. Learn how your comment data is processed.