javascript - syntax error, unexpected '(', expecting variable (T_VARIABLE) or '$' - Stack Overfl

I'm trying to build tabbed panels where a user can retain at current tab after refresh, updates et

I'm trying to build tabbed panels where a user can retain at current tab after refresh, updates etc. So, I'm trying to apply this script to my web as a tabbed panel but can't figure out what causes the syntax error. I've been trying to solve the problem for days regarding tabs but can seem to solve it. Btw, I don't use cookies and jquery. I don't use cookies because my friends (my clients) don't use cookies on their terminals. second, I don't use jquery (even though it's better) I prefer php only. please help thank you.

<?php 
 $('ul.tabs').each(function(){
    // For each set of tabs, we want to keep track of
    // which tab is active and its associated content
    var $active, $content, $links = $(this).find('a');
    // If the location.hash matches one of the links, use that as the active tab.
    // If no match is found, use the first link as the initial active tab.
    $active = $($links.filter('[href="'+location.hash+'"]')[0] || $links[0]);
    $active.addClass('active');
    $content = $($active[0].hash);
    // Hide the remaining content
    $links.not($active).each(function () {
      $(this.hash).hide();
    });
    // Bind the click event handler
    $(this).on('click', 'a', function(e){
      // Make the old tab inactive.
      $active.removeClass('active');
      $content.hide();
      // Update the variables with the new link and content
      $active = $(this);
      $content = $(this.hash);
      // Make the tab active.
      $active.addClass('active');
      $content.show();
      // Prevent the anchor's default click action
      e.preventDefault();
    });
  }); ?>
<html>
<head>
</head>
<body>
<ul class='tabs'>
    <li><a href='#tab1'>Tab 1</a></li>
    <li><a href='#tab2'>Tab 2</a></li>
    <li><a href='#tab3'>Tab 3</a></li>
  </ul>
  <div id='tab1'>
    <p>Hi, this is the first tab.</p>
  </div>
  <div id='tab2'>
    <p>This is the 2nd tab.</p>
  </div>
  <div id='tab3'>
    <p>And this is the 3rd tab.</p>
  </div>
  </body>
  </html>

I'm trying to build tabbed panels where a user can retain at current tab after refresh, updates etc. So, I'm trying to apply this script to my web as a tabbed panel but can't figure out what causes the syntax error. I've been trying to solve the problem for days regarding tabs but can seem to solve it. Btw, I don't use cookies and jquery. I don't use cookies because my friends (my clients) don't use cookies on their terminals. second, I don't use jquery (even though it's better) I prefer php only. please help thank you.

<?php 
 $('ul.tabs').each(function(){
    // For each set of tabs, we want to keep track of
    // which tab is active and its associated content
    var $active, $content, $links = $(this).find('a');
    // If the location.hash matches one of the links, use that as the active tab.
    // If no match is found, use the first link as the initial active tab.
    $active = $($links.filter('[href="'+location.hash+'"]')[0] || $links[0]);
    $active.addClass('active');
    $content = $($active[0].hash);
    // Hide the remaining content
    $links.not($active).each(function () {
      $(this.hash).hide();
    });
    // Bind the click event handler
    $(this).on('click', 'a', function(e){
      // Make the old tab inactive.
      $active.removeClass('active');
      $content.hide();
      // Update the variables with the new link and content
      $active = $(this);
      $content = $(this.hash);
      // Make the tab active.
      $active.addClass('active');
      $content.show();
      // Prevent the anchor's default click action
      e.preventDefault();
    });
  }); ?>
<html>
<head>
</head>
<body>
<ul class='tabs'>
    <li><a href='#tab1'>Tab 1</a></li>
    <li><a href='#tab2'>Tab 2</a></li>
    <li><a href='#tab3'>Tab 3</a></li>
  </ul>
  <div id='tab1'>
    <p>Hi, this is the first tab.</p>
  </div>
  <div id='tab2'>
    <p>This is the 2nd tab.</p>
  </div>
  <div id='tab3'>
    <p>And this is the 3rd tab.</p>
  </div>
  </body>
  </html>
Share Improve this question edited Sep 25, 2018 at 15:11 Manikandan C 6981 gold badge9 silver badges22 bronze badges asked Jan 2, 2016 at 3:55 Linda MayLinda May 871 gold badge2 silver badges15 bronze badges 10
  • 3 um, you're running JS inside PHP,. Hence, the error. Those are 2 different animals altogether. – Funk Forty Niner Commented Jan 2, 2016 at 3:56
  • 3 want to see some magic? replace <?php with <script> and ?> with </script> ;-) – Funk Forty Niner Commented Jan 2, 2016 at 3:57
  • This is all jQuery. Right Ralph? @Fred-ii- – Jay Blanchard Commented Jan 2, 2016 at 4:01
  • 1 Si signore Sam @JayBlanchard hey... what're you doing up at this houir? ah, a late night movie I'll bet. The one about where Wile E. gets the Road Runner? – Funk Forty Niner Commented Jan 2, 2016 at 4:03
  • 10-4 Ralph! @Fred-ii- – Jay Blanchard Commented Jan 2, 2016 at 4:04
 |  Show 5 more ments

1 Answer 1

Reset to default 2

You're using Javascript (jQuery to be precise) syntax inside PHP. Hence, the error.

syntax error, unexpected '(', expecting variable (T_VARIABLE) or '$'

  • Those are 2 different animals altogether.

Replace <?php with <script> and ?> with </script> and your code will work.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744535960a4579431.html

相关推荐

  • Python | python3.8安装教程(Windows环境)

    摘要&#xff1a;本文将介绍python的安装教程&#xff0c;适用于首次安装python的用户 官网链接&#xff1a;https:www.python 配置说明 运行环境&#xff1a;Wind

    1小时前
    00
  • Windows下的python安装教程_2024年10月最新最详细的安装指南

    文章目录 前言一、下载python二、安装python三、验证环境四、配置环境变量&#xff08;可选&#xff09;总结 前言 Python 是一种广泛使用的高级编程语言&#xff0c;以其简洁易读的语法和强大的

    1小时前
    00
  • MCP实战

    前言最近热衷于找一些好玩的MCP,集成在cursor中,给大模型外挂许多有趣的功能,例如:什么是MCP?本地如何开发MCP ServerMCP实战 | cursor 如何一句话操作 gitHub 代码库cursor 如何调用 MCP ser

    1小时前
    00
  • 方法分享

    作者,Evil Genius现在的日子,关税在涨,物价在涨,钱是越来越难挣了。什么东西在跌呢?工资在跌,房价也跌,房租反而涨了,生活的压力感觉越来越大了。对于生信分析而言,什么东西是最重要的?尤其是空间转录组的分析?很显然,硬件是服务器,软

    1小时前
    00
  • 很干!dockerfile最佳实践

    为什么你打包的镜像那么大?为什么打包过程耗时这么久?导致整个部署的效率很低,如果你有这样的疑问,那么很多时候是因为dockerfile的问题,这篇文章将会深入介绍dockerfile的最佳实践,帮助你构建更高效、更小、更可维护的镜像。缓存机

    1小时前
    00
  • Power BI Vega 条形纵向折线组合图表

    条形图和纵向折线图组合常用来展示绝对值和率值的组合。之前在知识星球分享过SVG的版本(使用内置表格加载),今天换一种实现方式,使用Deneb视觉对象:把需要展示的维度和指标拖拽到Deneb,本例维度为城市,绝对值为[kpi]度量值,率值为[

    53分钟前
    00
  • windows11 x64 操作系统不支持Xilinx ISE 14.4版本,解决方案:创建windows7 x64 虚拟机,再安装Xilinx ISE 14.4。

    点击 下面的xsetup.exe可执行文件&#xff0c;弹出下面的报错框 &#xff1a; 于是我通过网上阅读文章进行了一系列的尝试 。 省流&#xff1a;1-7步骤都可以不用看&#xff0c;这些都是

    49分钟前
    00
  • 扣子空间能战否?我看行~

    最近扣子推出了新模块:扣子空间,功能和前段时间刷屏的Manus类似,就是帮你一步到位完成任务。扣子空间地址:扣子空间现在还没完全开放,需要有邀请码,没邀请码的同学先加入等候名单,然后静静等待~这个扣子空间和普通的AI聊天工具有什么不一样呢?

    43分钟前
    00
  • 铜缆以太网19

    40G-CR4100G-CR10 (C85)PCS (C82)(二)发送方向发送过程发送过程基于从XLGMIICGMII接收到的TXD<63:0>和TXC<7:0>信号生成块。1个XLGMIICGMII数据发送

    40分钟前
    00
  • 计算机无法查看图片,Win7系统提示&quot;windows照片查看器无法打开此图片&quot;的解决方法...

    Win7系统经常会用Windows照片查看器查看图片&#xff0c;但是有位用户查看图片的时候出现提示“windows照片查看器无法打开此图片”,为什么会出现这样的问题呢&#xff1f;这是因为此文件可能已损坏、损毁或过大。

    36分钟前
    00
  • 飞书多维表格批量转换

    之前一直以为,飞书多维表格是专门用来协作的,除了漂亮一点也没啥。近期偶然得知飞书多维表格已经新增了 AI 的加持,变得不得了了,今天就来分享一个场景:不同数据库 SQL 格式的批量转换。假设你现在有一批 Oracle 脚本,现在因为某种原因

    36分钟前
    00
  • CMeas度量体系建设:让数据驱动更科学

    本文来自腾讯蓝鲸智云社区用户: CanWay研发效能度量在企业数字化转型中至关重要。它有助于企业全面量化研发过程,洞察业务绩效,识别效能瓶颈或提效机会、优化资源配置,并为决策提供有力支撑,持续推动企业研发效能优化提升。目前,效能度量已不局限

    35分钟前
    00
  • Fabric8 Kubernetes 日志工具实践

    最近在使用 Fabric8 Kubernetes Client 的过程中发现了新大陆一样,感觉利用这个库可以进行很多有趣的功能尝试,其中一个便是日志的本地化。原因无他,rancher 页面性能实在太差了,经常性的暂停工作,碰到故障排查的时候

    33分钟前
    00
  • OceanBase 单机版可以大批量快速部署吗? YES

    OceanBase的单机版已经开放给一些老师测试了,有幸被邀请进行单机测试,这次可以测试的是商业版,我已经好久没有尝试一个商业版线下的数据库试用了,上一次还是SQL SERVER 2019 的180天版本。测试企业OB版本测试企业OB版本目

    28分钟前
    00
  • windows7计算机图片,win7照片查看器无法显示图片计算机可用内存不足 需要技巧...

    很多人在使用win7图片查看器的时候&#xff0c;查看图片都有遇到内存不足的情况&#xff0c;却又不知道是什么原因&#xff0c;该怎么处理&#xff0c;那么今天我们就一起来看看吧。 工具材料 ●电脑

    25分钟前
    20
  • Oracle中删除的列数据可以进行恢复么?

    有朋友提出闪回可以恢复删除的列(包括数据),这个可行么?实践是检验真理的唯一标准,创建一张测试表,代码语言:javascript代码运行次数:0运行复制CREATE TABLE t_flash_01 (id NUMBER, c1 varch

    25分钟前
    20
  • R中单细胞RNA

    引言本系列开启 R 中scRNA-seq数据分析教程[1],持续更新,欢迎关注,转发!想要获取更多教程内容或者生信分析服务可以添加文末的学习交流群或客服QQ:941844452。简介RNA 速度分析最早由 La Manno 等人在 2018

    23分钟前
    20
  • AI|微信又又又有大动作了,直接把Deepseek变成了你的微信好友!

    腾讯又又又放大招了!在全球都在AI的浪潮中,以及年初Deepseek横空出世,使得中国的AI开始“吊打”海外的AI后,国内的AI使用也如雨后春笋般层出不穷。但是对于很多人来说AI的使用依然是一个门槛儿,手机上需要安装APP或者各种小程序跳转

    16分钟前
    20
  • OFC 2025:IBM开发应用于CPO的高密度聚合物波导光子模块

    一、技术背景:突破电互连瓶颈在服务器硬件中,计算单元的带宽每两年以约 3 倍的速度增长,而互连技术仅以 1.4 倍的速度发展,导致 “带宽鸿沟” 持续扩大。传统可插拔收发模块虽能扩展传输距离,但在高密度集成和功耗上存在局限。

    8分钟前
    00
  • CICD界一颗冉冉升起的新星,主打一个各种可以

    介绍在云计算与容器化技术高速发展的当下,多服务器环境下的软件构建与部署效率已成为开发者亟待突破的瓶颈。Komodo作为开源工具领域的革新者,凭借其高度灵活性、无限扩展潜力及人性化设计,为DevOps团队与独立开发者提供了全链路的解决方案。这

    6分钟前
    00

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信