Jquery禁用无效

时间:2015-03-01 08:25:41

标签: javascript jquery jquery-ui

<!DOCTYPE html>
<html>
<body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>

<script>
$(document).ready(function () {
    $("input[name='data[Store][id][]']").change(function () {
if ($("input[name='data[Store][id][]']").is(':checked')) {
        var input_value = parseFloat($(this).val());
        var brand= $(this).closest('tr').find('#brand').text();


        var number1 = $(this).closest('tr').find('input[name="data[store][stock_received][]"]').attr('disabled', 'disabled');

        }else{
        var number1 = $(this).closest('tr').find('input[name="data[store][stock_received][]"]').prop("disabled", false);

        }

 });
});
</script>
<table style="width:100%">
  <tr>
    <td>Jill</td>
    <td>Smith</td>      

  </tr>
  <tr>
    <td><input id='tmpid' name="data[store][stock_received][]" ></td>       
    <td><input type='checkbox' name='data[Store][id][]'></td>
  </tr>
    <tr>
    <td><input id='tmpid' name="data[store][stock_received][]"></td>        
    <td><input type='checkbox' name='data[Store][id][]'></td>
  </tr>
  <tr>
    <td><input id='tmpid' name="data[store][stock_received][]"></td>        
    <td><input type='checkbox' name='data[Store][id][]'></td>
  </tr>
  <tr>
    <td><input id='tmpid' name="data[store][stock_received][]"></td>        
    <td><input type='checkbox' name='data[Store][id][]'></td>
  </tr>
  <tr>
    <td><input id='tmpid' name="data[store][stock_received][]"></td>        
    <td><input type='checkbox' name='data[Store][id][]'></td>
  </tr>
</table>

</body>
</html>

jquery disable无法正常工作,我想在id=tmpid附近禁用name='data[Store][id][]'。 目前我在name='data[store][stock_received][]'附近使用name='data[Store][id][]'名称。 个人复选框工作正常。如果我选择全部,那么我取消选中,然后它无法正常工作

1 个答案:

答案 0 :(得分:1)

1)ID应该是唯一的

2)您在字符串

上使用parseFloat()

3)$("input[name='data[Store][id][]']").is(':checked')似乎是正确的 应为$(this).is(":checked")

&#13;
&#13;
$(document).ready(function() {
  $("input[name='data[Store][id][]']").change(function() {
    if ($(this).is(':checked')) {
      var input_value = $(this).val();
      var brand = $(this).closest('tr').find('#brand').text();


      var number1 = $(this).closest('tr').find('input[name="data[store][stock_received][]"]').attr('disabled', 'disabled');

    } else {
      var number1 = $(this).closest('tr').find('input[name="data[store][stock_received][]"]').prop("disabled", false);

    }

  });
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<table style="width:100%">
  <tr>
    <td>Jill</td>
    <td>Smith</td>

  </tr>
  <tr>
    <td>
      <input class='tmpid' name="data[store][stock_received][]">
    </td>
    <td>
      <input type='checkbox' name='data[Store][id][]'>
    </td>
  </tr>
  <tr>
    <td>
      <input class='tmpid' name="data[store][stock_received][]">
    </td>
    <td>
      <input type='checkbox' name='data[Store][id][]'>
    </td>
  </tr>
  <tr>
    <td>
      <input class='tmpid' name="data[store][stock_received][]">
    </td>
    <td>
      <input type='checkbox' name='data[Store][id][]'>
    </td>
  </tr>
  <tr>
    <td>
      <input class='tmpid' name="data[store][stock_received][]">
    </td>
    <td>
      <input type='checkbox' name='data[Store][id][]'>
    </td>
  </tr>
  <tr>
    <td>
      <input class='tmpid' name="data[store][stock_received][]">
    </td>
    <td>
      <input type='checkbox' name='data[Store][id][]'>
    </td>
  </tr>
</table>
&#13;
&#13;
&#13;