doucong7963 2014-10-17 12:32
浏览 31
已采纳

使用参数单击按钮运行Jquery / JS函数

I have 5 buttons all of them need to run the same function on click or onSubmit idk what the best way to do this is..But i need to pass the buttons ID as a parameter to the function. The buttons are running the function BuyItem(button id), I need the button to be past so i can run the same function and just distinguish which they are buying based off the button id being passed.

The buttons are being created in my php file

<input type='button' id='$id' name='$id' onSubmit="funciton($id)" style='width:185px;'value='Buy Tool'>

I dont know if thats how i should call the function but when the button is click i need to have the id passed to the function

  • 写回答

2条回答 默认 最新

  • dongnao2582 2014-10-17 12:37
    关注

    this.id will give the current id of the element

    <input type='button' id='$id' name='$id' onSubmit="Funciton(this.id)" style='width:185px;'value='Buy Tool'>
    

    then your js would be

    Funciton(id){
        alert(id);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动