JavaScript:用“or”声明 VAR陈述
类似
var $page_products = $page_name == 'products-uninterruptible-power-supply.php' OR 'products-uninterruptible-power-supply-np2031.php';
该代码与我已经尝试使用的
var $page_products = $page_name == 'products-uninterruptible-power-supply.php' || 'products-uninterruptible-power-supply-np2031.php';
,但它仍然无法正常工作。提前致谢!
the code is something like this
var $page_products = $page_name == 'products-uninterruptible-power-supply.php' OR 'products-uninterruptible-power-supply-np2031.php';
i already tried using
var $page_products = $page_name == 'products-uninterruptible-power-supply.php' || 'products-uninterruptible-power-supply-np2031.php';
but it is still not working. thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
假设您的目的是声明一个变量
$page_products
,如果$page_name
等于这两个字符串之一,则该变量将设置为 true,否则设置为 false,请执行以下操作:编辑:我刚刚注意到两个页面名称都以相同的四个单词开头,因此您不必与每个字符串进行比较,而是可以测试
$page_name
中的值是否以这些单词开头,例如, :Assuming your intention is to declare one variable,
$page_products
, which will be set to true if the$page_name
is equal to either of those two strings and false otherwise, do this:EDIT: I just noticed that both page names start with the same four words, so instead of comparing to each string it may suit you to test whether the value in
$page_name
starts with those words, e.g.,:这应该有效
This should work
如果您想有条件地分配文件名,那么您将需要三元运算符:
If you want to assign the file name conditionally, then you'll want the ternary operator: