代码是这样的

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';


但仍然无法正常工作。提前致谢!

最佳答案

假设您打算声明一个变量$page_products,如果$page_name等于这两个字符串中的任何一个,则将其设置为true,否则将设置为false:

var $page_products = $page_name == 'products-uninterruptible-power-supply.php'
           || $page_name == 'products-uninterruptible-power-supply-np2031.php';


编辑:我只是注意到两个页面名称都以相同的四个词开头,因此与其比较每个字符串,它可能更适合您测试$page_name中的值是否以这些词开头,例如:

var $page_products =
           $page_name.indexOf('products-uninterruptible-power-supply') === 0;

10-04 15:35