我运行此脚本,以显示不同的菜单,手机:铬未捕获的语法错误:意外的标记<
<script>
jQuery(document).ready(function($){
if ($(window).width() > 750){
<?php wp_nav_menu(array('theme_location' => 'primary', 'container' => false, 'menu_class' => 'menu clearfix')); ?>
}else{
<?php wp_nav_menu(array('theme_location' => 'mobile', 'container' => false, 'menu_class' => 'menu clearfix')); ?>
}
});
</script>
但我通过镀铬得到错误“未捕获的SyntaxError:意外的标记<”我指着该行:
编辑:好吧,不知道在js中运行php有问题。 那么我的情况有什么合适的解决方案?我知道我只能使用CSS媒体查询和显示属性,但它对性能不利,不是吗?
这是因为您的PHP代码正在JS脚本块内生成HTML,语法错误。我不确定你试图达到什么目的。 –
你想用php代码实现什么? –
我试图显示菜单是注册与'register_nav_menu()' – Avishay28