duanbei7035 2017-08-10 13:39
浏览 55
已采纳

多个共享一个javascript函数的按钮

I am using a foreach loop to load data from mysql table using php.

Now I have a button with a javascript function next to each foreeach set of data to display the data.

The problem is, the button only works on the very first fetched data in the foreach loop. I am not sure what the problem is?

Here is my code https://jsfiddle.net/7qL2osp5/

I am using this script btw

<script type="text/javascript">
  function bigger(){
        document.getElementById("approvals-data-box").style.width="95%";
        document.getElementById("actual-data").style.display="block";
  }

</script>

Thanks

  • 写回答

4条回答 默认 最新

  • doushe7934 2017-08-10 13:50
    关注

    id is used for one specific element. You can only have one element with the same id.

    What you need to do is give them all different ids and then pass in the id to the function. You also need classes for the styling.

    IDs are for specific elements. Classes are for element types.

    Here's a working version:

    https://jsfiddle.net/7qL2osp5/1/

    In CSS, you use the . for classes and the # for ids. This may be a good time to try to learn jQuery since you're just starting out.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)