zl程序教程

您现在的位置是:首页 >  后端

当前栏目

js实现在字符串中提取数字

JS 实现 字符串 数字 提取
2023-06-13 09:15:07 时间

<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312"/>
<title>js实现在字符串中提取数字</title>
<scriptlanguage="javascript"type="text/javascript">
functiongetNum(text){
varvalue=text.replace(/[^0-9]/ig,"");
alert(value);
}
</script>
</head>


<body>
<inputtype="text"id="btn_getNum"/>
<inputtype="button"value="得到数字"onclick="getNum(btn_getNum.value);"/>
</body>
</html>