<分区>
标签 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>
最佳答案
检查这个fiddle
$(document).ready(function() {
var str = "party hat 1 for men";
alert(str.substr(0, str.indexOf('1')+1));
});
关于javascript - 从现有产品描述中删除文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40930887/