javascript不在模式弹出窗口中触发

时间:2020-06-29 09:08:46

标签: javascript php bootstrap-modal

我有模式弹出窗口,单击按钮即可打开。我有一个具有用户类型的选择下拉列表,根据该用户类型,它从mysql表中获取相应的数据并填充到另一个选择下拉列表中。我正在使用.on(change)函数,这是模式弹出菜单的select下拉列表:

<label for="inputEmail3" class="col-sm-4 col-form-label">User Type</label>
          <select name="user_type" id="user_type" class="form-control form-control-sm" style="width: 100%;" required="">
                            <option selected="selected" value="">Select user type </option>
                            <option  value="admin">Admin </option>
                            <option  value="manager">Manager </option>
                            <option  value="executive">Executive </option>
                        
                            </select>



            <label for="inputEmail3" class="col-sm-4 col-form-label">Employee/User</label>
          <select name="user" id="user" class="form-control form-control-sm" style="width: 100%;" required="" disabled>
                            <option selected="selected" value="">Select Employee </option>
                            </select>

我最初拥有的Javascipt:

<script type="text/javascript">
$(document).ready(function(){
$('#user_type').on(function() {
   var usertype = $(this).val();
   $('#user').prop( "disabled", false );

   
        $.ajax({
            type:'POST',
            url:'T_userData.php',
            data:'usertype='+usertype,
            success:function(html){
                //alert(html);
                $('#sub_prod').html(html);
                //$('#city').html('<option value="">Select state first</option>'); 
            }
        }); 
    
});
});
</script>

然后我将其更改为

 <script type="text/javascript">
 $(document).ready(function(){
 $('#trgtmodal').on("change","#user_type",function() {
    var usertype = $(this).val();
   $('#user').prop( "disabled", false );

   
        $.ajax({
            type:'POST',
            url:'T_userData.php',
            data:'usertype='+usertype,
            success:function(html){
                //alert(html);
                $('#sub_prod').html(html);
                //$('#city').html('<option value="">Select state first</option>'); 
            }
        }); 
    
});
});
</script>

仍然无法正常工作。如果需要,我可以发布整个Modal Popup HTML标记。请指教

0 个答案:

没有答案