我们可以在按钮的输入类型中给出两个值吗

Can we give two values in the input type of a button?

本文关键字:两个 按钮 类型 输入 我们      更新时间:2023-09-26

我必须在一个复选框中给定两个值,因为在这两个值上应该选中复选框。

我可以使用if条件吗?还是其他什么?我想不出什么好主意。

   <div class="Checkbox" style="width: 40px; height: 35px; margin-top: 3px;">
     <input type="checkbox" name="boxselector"  id="ROICheckBox"  onclick ="toggleCheckboxes(this);"   value="ROI" />
    <label for="ROICheckBox"  style="height: 10px; padding-bottom: 18px;" ></label>
   </div>

现在我又有一个值Pixel,它应该使用与ROI相同的复选框。我该怎么做??

$("[name=boxselector]").click(function(
                      myPixelSetSel = undefined;
                       mySel = new Box2();
                       if (this.value === "ROI"){
                           mySel.isROI = true;
                       }
                       else if (this.value === "Layer"){
                           mySel.isLayer = true;
                       }
                       else if (this.value === "Metrics"){
                           mySel.isMetrics = true;
                          myPixelSetSel = 1;
//                           mySel = undefined;
                       }
                        else if (this.value === "MeasBox"){
                           mySel.isMeasBox = true;
                       }
                       else if(this.value === "Pixel"){
                         myPixelSetSel = 1;
                         mySel = undefined;
                    }
                } else {
                    sel = {};
                    mySel = undefined;
                    myPixelSetSel = undefined;
                }     
        });
       });

当第一个值被选中并假设已提交时,为什么不拥有这两个值的数组?例如:看看这里:http://jsfiddle.net/csdtesting/vcfvmLsy/

$('form').submit(function() {
  var arr = [];
  var chkel = $('input[name="boxselector"]');
  var valueToAdd = "Pixel";
  if ($(chkel).is(':checked')) {
    if ($(chkel).val() == "ROI")
      arr.push($(chkel).val());
    arr.push(valueToAdd);
  }
  console.log(arr);
  alert(arr[0]);
  alert(arr[1]);
  // Prevent actual submit for demo purposes:
  return false;
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="Checkbox" style="width: 40px; height: 35px; margin-top: 3px;">
  <input type="checkbox" name="boxselector" id="ROICheckBox" onclick="toggleCheckboxes(this);" value="ROI" checked="checked" />
  <label for="ROICheckBox" style="height: 10px; padding-bottom: 18px;"></label>
</div>
<form>
  <input id='my_match' type='hidden' name='my_match[]' />
  <button>Submit</button>
</form>