2012-10-26 102 views
0

在窗体上,我有一个显示输入字段的无线电组。根据是否显示字段来调整字段。用户可以将表单备份,并使用适当的数据重新填充字段。我的问题是最初加载的广播组的形式为no(隐藏输入字段'),我想触发正在被监听器处理的事件。触发单选按钮更改

这是事件处理程序(#custodian is a < tr>):

$('.passCustodian').change(function(){ 
    $('#custodian').toggle(); 
}); 

这是重新填充表单字段功能的一部分:

if(typeof data["custodianData"][0] != 'undefined'){ 
    $("#requestForm").fillInputs(data["custodianData"][0]); 
    //$('.custodianYes').attr('checked',true); //this didn't work either 
    $('.passCustodian').trigger('change'); 
} 

你可以看到我尝试使用jQuery的触发事件,但它不起作用。任何帮助深表感谢!

回答

0

为此,您不需要触发事件。

使用此

if(typeof data["custodianData"][0] != 'undefined'){ 
    $("#requestForm").fillInputs(data["custodianData"][0]); 
    $('#custodian').toggle(); 
} 

if($('#custodianData').is(':checked')){ 
     $("#requestForm").fillInputs(data["custodianData"][0]); 
     $('#custodian').toggle(); 
    } 
+0

啊,应该已经看到,... –

相关问题