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>

评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据