刚学jquery,遇到一个问题!想用正则表达式在变量中得到的值加上第千个符号,但是遇到了一些障碍~在网上找到这样的语法replace(/\B(?
let num = 123456; $('.show').text(num.replace(/\B(?<!\.\d*)(?=(\d{3})+(?!\d))/g, ",")); <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <p class="show"></p>
将您的数字转换为字符串,因为替换功能仅适用于字符串
let num = 123456; $('.show').text(String(num).replace(/\B(?<!\.\d*)(?=(\d{3})+(?!\d))/g, ",")); <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <p class="show"></p>