使用正则表达式分隔每个组:
function iframe_url(path)
{
if (/[0][0-9][0-9][0-9]|1000/.test(path) )
{
window.frames[0].location.href = "http://www.stackoverflow.com";
}
else if (/[1][0-9][0-9][1-9]|2000/.test(path) )
{
window.frames[0].location.href = "http://meta.stackoverflow.com";
}
}
iframe_url("1000") //stackoverflow.com
iframe_url("1999") //meta.stackoverflow.com
使用模运算符进行余数检查也可以:
function iframe_url(path)
{
if (1000 % path < 1000)
{
window.frames[0].location.href = "http://www.stackoverflow.com";
}
else if (2000 % path < 2000)
{
window.frames[0].location.href = "http://meta.stackoverflow.com";
}
}