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

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

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

个人博客 http://www.sharedblog.cn/?post=215

	<!-- 简单写几个按钮 -->
	<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>

个人小程序已经上线(多多支持)

posted @ 2020-03-13 10:57  鹏仔先生  阅读(4)  评论(0)    收藏  举报  来源