我需要从字符串中提取数字
<p id="example">etc etc(5)</p>
<p id="example2">etc etc(-5)</p>
Run Code Online (Sandbox Code Playgroud)
我正在使用此代码
alert($("#example").text().match(/\((\d+)\)/)[1]);
Run Code Online (Sandbox Code Playgroud)
如果数字为正,则工作正常但在负数的情况下获得错误
Uncaught TypeError: Cannot read property '1' of null
Run Code Online (Sandbox Code Playgroud)
请帮我解决一下谢谢
| 归档时间: |
|
| 查看次数: |
6756 次 |
| 最近记录: |