简体   繁体   中英

Append input type property not working in jquery

I have table structure dynamic add row option. It makes a new row when I click add but problem is $("[name*=vehicle_type]").change(function () it's not work for append input field

Only work for this

<select name="vehicle_type[]" class="form-control company" id="company" required>
              <option value="type">Type</option>
</select>

But not works for this

$('#dynamic_field').append('<tr id="row'+i+'"><td><select name="vehicle_type[]" class="form-control company" id="company" style="width: 140px;" required><option value=""> Type</option>'+val_all_types+'</select></td></tr>');  
  });  

Here is jquery code

$("[name*=vehicle_type]").change(function () {
      //  alert('ok');
        var $type = $(this); 
        var $row = $type.closest("tr"); 
        var $cat = $("[name*=vehicle_category]", $row); 
        var $subcat = $("[name*=vehicle_sub_category]", $row);
        $.ajax({
            url: 'getCat',
            type: "get",
            data: { type: $type.val() },
            success: function(data) {
                $cat.empty();
                $subcat.empty();
                $.each(data, function (i, d) {
                    $cat.append($('<option>', {
                        value: d.id,
                        text : d.V_Category
                    }));
                });
            }
        });    
    });

您需要将$("[name*=vehicle_type]").change(function () { $(document).on("change", "[name*=vehicle_type]" , function() {$(document).on("change", "[name*=vehicle_type]" , function() {

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM