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

时间:2014-10-06 23:51:07

标签: javascript html

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

我可以使用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;
                }     
        });
       });

1 个答案:

答案 0 :(得分:0)

为什么在检查第一个值并且提交假设时,您没有这两个值的数组:例如: 看看这里:http://jsfiddle.net/csdtesting/vcfvmLsy/

&#13;
&#13;
$('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;
});
&#13;
<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>
&#13;
&#13;
&#13;