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 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝