如何在禁用的字段集中启用div元素?

时间:2016-07-29 17:55:29

标签: javascript jquery html css

我有一堆带有一堆元素的字段集。它已被禁用,但我希望在div中保持其中一个div及其所有子节点,同时禁用所有其他元素。这可能吗?无论是在JQuery还是CSS或其他任何东西!

离。我想启用“注释”但保持“纸张”禁用

<fieldset disabled>
  <div name="paper" class="form-control" style="width:100%; height:300px;border:1px solid black;">
    <input name="AddPaper" type="button" value="Add" class="btn btn-warning btn-xs" />
  </div>
  <div name="notes" class="form-control" style="width:100%; height:300px;border:1px solid black;">
    <input name="AddNotes" type="button" value="Add" class="btn btn-warning btn-xs" />
    <input name="saveNotes" type="button" value="Save" class="btn btn-success btn-xs" />
  </div>
</fieldset>

2 个答案:

答案 0 :(得分:1)

你需要在孩子身上设置它,你可以使用jQuery或JS轻松切换

&#13;
&#13;
<fieldset>
  <div name="paper" class="form-control" style="width:100%; height:300px;border:1px solid black;">
    <input disabled name="AddPaper" type="button" value="Add" class="btn btn-warning btn-xs" />
  </div>
  <div name="notes" class="form-control" style="width:100%; height:300px;border:1px solid black;">
    <input name="AddNotes" type="button" value="Add" class="btn btn-warning btn-xs" />
    <input name="saveNotes" type="button" value="Save" class="btn btn-success btn-xs" />
  </div>
</fieldset>
&#13;
&#13;
&#13;

或更改标记

&#13;
&#13;
fieldset fieldset {
  border: 0;
  padding: 0;
}
&#13;
<fieldset>
  <fieldset disabled>
    <div name="paper" class="form-control" style="width:100%; height:300px;border:1px solid black;">
      <input name="AddPaper" type="button" value="Add" class="btn btn-warning btn-xs" />
    </div>
  </fieldset>
  <fieldset>
    <div name="notes" class="form-control" style="width:100%; height:300px;border:1px solid black;">
      <input name="AddNotes" type="button" value="Add" class="btn btn-warning btn-xs" />
      <input name="saveNotes" type="button" value="Save" class="btn btn-success btn-xs" />
    </div>
  </fieldset>
</fieldset>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

我的建议是重新排列除您选择的元素之外的所有元素的禁用属性:

&#13;
&#13;
$(function () {
  $('fieldset:disabled').prop('disabled', false).children().each(function(i, e) {
    var jEle = $(e);
    if (jEle.attr('name') != 'notes') {
      jEle.find('*').prop('disabled', true).css('background', 'red');
    }
  });
});
&#13;
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>

<fieldset disabled>
    <div name="paper" class="form-control" style="width:100%; height:300px;border:1px solid black;">
        <input name="AddPaper" type="button" value="Add" class="btn btn-warning btn-xs" />
    </div>
    <div name="notes" class="form-control" style="width:100%; height:300px;border:1px solid black;">
        <input name="AddNotes" type="button" value="Add" class="btn btn-warning btn-xs" />
        <input name="saveNotes" type="button" value="Save" class="btn btn-success btn-xs" />
    </div>
</fieldset>
&#13;
&#13;
&#13;