0

problem 1:

The following code should enable/ disable an dynamically added input field by jquery, but it does not work as expected:

$(document).ready(function () {
    $('#auto').change(function () {
        if ($(this).val() == 1) {
            $('input[id="speed_car"]').prop('disabled', false).css('background', '').val('4')
        } else {
            $('input[id="speed_car"]').prop('disabled', true).css('background-color', '#03f').val('')
        }
    });
});

Problem2: If i save the field and reload the page it works, but only for the first < tr > (which contains other input fields and selects).

How should i change the code so that it will work correctly?

Here's part of the code which add's the row:

  var modell = <?php echo $modell; ?>;
   .
   .
   .
  html += '    <td class="left"><select name="car_modell[' + modell + '][auto]">'; 
  html += '     <option value="1" selected="selected"><?php echo $text_enabled; ?></option>';
  html += '     <option value="0"><?php echo $text_disabled; ?></option>';
  html += '    </select></td>';
  html += '    <td class="left"><input type="text" maxlength="1" name="car_modell[' + modell + '][speed_car]" value="4" size="3" /> </td>'; 
  ecc...

Thanks in advance for helping.

4

1 回答 1

1

您应该使用“on”功能。看这里:http ://api.jquery.com/on/

jQuery Binds on Load,但“on”会导致它在那一刻评估/绑定。

$("#dataTable tbody tr").on("click", function(event){
  alert($(this).text());
});
于 2013-06-18T22:17:56.200 回答