首页javascriptpjQuery HTML Element - 如何仅对段落中的数字应用CSS

jQuery HTML Element - 如何仅对段落中的数字应用CSS

我们想知道如何仅对段落中的数字应用CSS。

<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.9.1.js'></script>
<style type='text/css'>
span {
  color: blue
}
</style>
<script type='text/javascript'>
$(window).load(function(){
    $('p').html(function(index, value) {
        return value.replace(/(\d+)/g, '<span>$1</span>');
    });
});
</script>
</head>
<body>
  <p>Text and numbers: 123</p>
  <p>123 and text</p>
</body>
</html>