duanjuelu8874 2011-08-29 09:37
浏览 39
已采纳

在Javascript中录制按钮ID

I am trying to create an item selection menu, where the user is presented with multiple buttons to pick their choices. I am creating several divs with PHP.

     <div id="h1-1"><input type="button" value="h1-1" onclick="recordValue()"></div>
     <div id="h1-2"><input type="button" value="h1-2" onclick="recordValue()"></div>

I would like to record all the values of buttons pressed and show these values via Ajax. Then when user is done selecting and presses submit I will insert these into MSSQL database.

  • How do I record button values to an array with Javascript?
  • How do I then show what was pressed?
  • Where could I execute some filtering of the selections (e.g. if h1-1 was pressed i do not want them to be able to select h2-1) ?
  • 写回答

2条回答 默认 最新

  • dongya5893 2011-08-29 09:56
    关注

    I would keep the value in an array.
    change you onclick part to
    onclick="recordValue(this)"
    and create an array outside the scope of the recordValue function wherever you declare it

    var values = [];
    function recordValue(element) {
        values.push(element.value);
        // code here to display value somewhere on the page
    }
    

    and then somewhere listen for the form's submit event and then send the data in your array via ajax to your server.

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

报告相同问题?

悬赏问题

  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线