1

这将删除最后一个单词。我如何得到最后一个字(条纹)?

var BaseShirtURL = "Base Shirt Draped with Fabric Stripe";
BaseShirtURL = BaseShirtURL.substring(0, BaseShirtURL.lastIndexOf(" "));
alert(BaseShirtURL);
4

2 回答 2

6

要获得最后一句话:

BaseShirtURL.split(' ').pop();

要删除最后一个单词,您可以这样做:

BaseShirtURL = BaseShirtURL.replace(/\w+$/,'');
于 2013-04-05T02:00:31.620 回答
1

这应该这样做:

var BaseShirtURL = "Base Shirt Draped with Fabric Stripe";
var stripe = BaseShirtURL.substring(BaseShirtURL.lastIndexOf(" ") + 1,
    BaseShirtURL.length());
alert(stripe);
于 2013-04-05T01:59:57.380 回答