如何在创建的字段上应用 .change 函数 b 其他字段的 .change 函数

How to apply the .change function on the field which is created b the .change function of some other field?

本文关键字:change 函数 字段 其他 应用 创建      更新时间:2023-09-26

此函数正在更改部件号(pno)字段时创建一个进程名称(prc)字段,现在我想要更改进程名称的过程特征字段,但是进程名称上的.change函数不起作用($('#prc').change(function(){});此功能不起作用)

 $('#pno').change(function(){
   var partno=$("#pno option:selected" ).val();
   $.ajax({ 
       cache: false,
       dataType: "html",
       type: "POST", 
       evalScripts: true,
       url: '<?php echo Router::url(array('controller'=>'Partconfs','action'=>'addpro'));?>',
       data: ({partno:partno}), 
       success: function(result){
         var pch=result.split('//');
         var plen=pch.length;
         var str="";
         $('#fid').html('');        
         str='<tr><td><br><b>PROCESS NAME</b><br><br></td></tr><tr><td><select name="process_name" label="" id="prc" style="height:30px; margin-top:-5px; min-width:190px; width:auto;" ><option value="">Select any</option>';
         $.each(pch,function(i,v){
           str += '<option value="'+v+'">'+v+'</option>';
         });
        str +='</select></td></tr>';
        $('#fid').append(str);
      }
    });
});

您需要直接在此行之后添加事件侦听器:

$('#fid').append(str);

当节点已准备好附加事件侦听器时,或者您需要在新<select>写入 DOM 之前从可用的父节点委派事件。

$('#fid').on('change', '#prc', function() {
   // do your stuff
});

这是通过将事件附加到有效组件来工作的,但仅在更改元素的选择器(在 #fid 下方)与选择器"#prc"匹配时才触发

您必须在动态字段上使用 on 函数。http://api.jquery.com/on/