【问题标题】:get value of the selected checkbox from matrix table从矩阵表中获取选定复选框的值
【发布时间】:2018-08-07 03:41:36
【问题描述】:

我在 asp.net web 表单中使用 html 设计了一个矩阵表,所以如果用户单击复选框,我希望立即显示所选行的名称以及所选列的名称。它的输出应该是这样的:Chlor-Alkali Relationship 请看下面的截图,但它会返回行索引和列索引。

下面是代码:

【问题讨论】:

  • 如果您希望人们提供帮助,您需要发布您已经尝试过的代码,以使其正常工作,然后一旦人们看到您付出了一些努力,他们就会倾向于提供帮助你。

标签: javascript html asp.net


【解决方案1】:

您可以使用文档选择器和检查属性获取检查输入的值:

function myFunction() {
  // get all checkboxes
  const checkBoxes = document.getElementsByClassName("selectableType");
  var result = "";

  // iterate over them
  for (var box = 0; box < checkBoxes.length; box ++) {

    // check if single checkbox is checked
    if (checkBoxes[box].checked === true) {

      // and do your needed magic here :D
      console.log(">", checkBoxes[box].value);
      result += checkBoxes[box].value + "\n";
    }
  }

  // just an example to show results
  alert (result === "" ? "No result" : "Selected inputs are\n" + result);
}

Check here a working example

【讨论】:

    猜你喜欢
    • 2014-02-08
    • 1970-01-01
    • 1970-01-01
    • 2017-04-18
    • 1970-01-01
    • 2015-07-30
    • 2015-02-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多