从现有产品说明中删除文本

时间:2016-12-02 11:11:58

标签: javascript jquery css

我正在使用代码在产品说明中创建换行符,这样可以正常工作。

但是现在我还需要正确的代码来删除" 1"之后发生的任何事情。在描述中。有人可以帮忙吗?



$('#description').html(function(i, h) {
  return h.substr(0, h.indexOf('1') + 1);
});

$('#description').html(function(i, h) {
  return h.substr(0, h.indexOf('2') + 2);
});

$('#description').html(function(i, h) {
  return h.substr(0, h.indexOf('3') + 3);
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="description">party hat 1 for men</div>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:0)

试试这个

$('#description').html(function(i, h) {
  return h.split('1')[0] + 1;
})

答案 1 :(得分:0)

检查此fiddle

 $(document).ready(function() {
        var str = "party hat 1 for men";

    alert(str.substr(0, str.indexOf('1')+1));
});
相关问题