2014-02-12 327 views
0

我有下面的代码。目标是检查Name变量是否以TBD开头。如果这样做,整个变量将被填充到另一个位置。但是,当且仅当它以“TBD - Hot”开头才会被区别对待。检查字符串是否以另一个字符串开头?

<script type = "text/javascript"> 

if ("%%%Name%%%"=="TBD") {document.write('<iframe width="100%" height="550" frameborder="0" scrolling="yes" marginheight="0" marginwidth="0" src=""></iframe>'); 
} 
else if ("%%%Name%%%"=="TBD - HOT") {document.write('<iframe width="100%" height="550" frameborder="0" scrolling="yes" marginheight="0" marginwidth="0" src=""></iframe>'); 
} 
else {document.write('<iframe width="100%" height="550" frameborder="0" scrolling="yes" marginheight="0" marginwidth="0" src=""></iframe>'); 
} 

</script> 

回答

0

您还可以在这里

if ((/^(TBD - HOT).*/).test(str) === 0) { 

} else if ((/^(TBD).*/).test(str) === 0) { 

} else { 

} 
使用正则表达式
相关问题