<分区>
这是一个很简单的问题,但是因为我才学这门语言一个星期,所以还没有找到答案。以下两行之间发生错误,因为 Regex
随机为 null,但是我如何检查它是否为 null,所以 itd 不会抛出错误?
var Regex = /\<span class="currency-robux">([\d,]+)\<\/span\>/
var PriceSelling = data.match(Regex)[1]
标签 javascript regex
<分区>
这是一个很简单的问题,但是因为我才学这门语言一个星期,所以还没有找到答案。以下两行之间发生错误,因为 Regex
随机为 null,但是我如何检查它是否为 null,所以 itd 不会抛出错误?
var Regex = /\<span class="currency-robux">([\d,]+)\<\/span\>/
var PriceSelling = data.match(Regex)[1]
最佳答案
像这样:
var Regex = /<span class="currency-robux">([\d,]+)<\/span>/;
var PriceSelling = data.match(Regex);
PriceSelling = PriceSelling ? PriceSelling[1] : '';
if (PriceSelling.length < 1) {
alert('Nothing!');
}
关于javascript - 检查是否为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21961009/
相关文章:
regex - Perl 正则表达式 : replace placeholder with variable content in template
javascript - 将状态更改从 onChange 事件传递给父级
asp.net - 使用 JavaScript 禁用 ASP.NET 3.5 应用程序中的提交按钮会破坏 BlackBerry 提交
javascript - Jquery $ ('#div' ).show().delay(5000).hide();不起作用
javascript - 在 Javascript 中检测图像是否损坏