加载页面后如何设置单选按钮的默认值?

how to set the default value of radio buttons after loading page?

我使用 OpenERP 7,我有 2 个单选按钮可以更改 table 的值。 我创建了一个调用 python 函数执行 sql 查询的事件,之后我必须重新加载页面以显示 table 蒙山新值。但问题是单选按钮采用默认值!所以用户只有一个选择,所以我必须在重新加载页面后设置单选按钮的默认值。这是我的 Qweb 代码:

<t t-if="number === 2">
        <table  style="margin-left:360px;margin-top:0px;margin-bottom:0px;">
            <tr>
                <td style="text-align:left;font-size:12px;"><b>Jusqu'au mois courant:</b></td>
                <td>
                   <input type="radio" id="radio_budget_cumulee_jusque_mois_courant" value="courant" name="radio_budget_cumulee" checked="checked"/>

                </td> 
            </tr> 
             <tr>      
                 <td style="text-align:left;font-size:12px;"><b>Jusqu'au fin d'année:</b></td>
                <td>   
                   <input type="radio" id="radio_budget_cumulee_jusque_fin_anneee" value="fin" name="radio_budget_cumulee"/>
                </td> 
            </tr>
        </table>
       <div id="itkbudg"> 
        <div  t-attf-id="#{view.element_id}_action_#{column_index}_#{action_index}" class="oe_content" t-att-style="action.attrs.fold ? 'display: none;' : 'height: 220px;overflow-x: hidden;overflow-y: auto;padding: 0 12px 1px;'"></div>
        </div> 
    </t>

这是我的 Javascript 代码:

    $("#radio_budget_cumulee_jusque_mois_courant, #radio_budget_cumulee_jusque_fin_anneee").change(function(){


            est_jusqu_mois_courant=self.$el.find('#radio_budget_cumulee_jusque_mois_courant').is(':checked')
            est_jusqu_finannee=self.$el.find('#radio_budget_cumulee_jusque_fin_anneee').is(':checked')


            var mod=new instance.web.Model("itk.compta.dashboard");
            mod.call("itk_compta_dashboard_fct_changer_vue",[est_jusqu_mois_courant],{}).done(function(res) {



            });

            self.do_action({
                type: 'ir.actions.client',
                tag: 'reload',
        });



           // $radios.filter('[value=fin]').prop('checked', est_jusqu_finannee);
            //$radios.filter('[value=courant]').prop('checked', est_jusqu_mois_courant);


            //I tried to use this code
            var $radios = $('input:radio[name=radio_budget_cumulee]');
            $radios.filter('[value=fin]').attr('checked', est_jusqu_finannee);
            $radios.filter('[value=courant]').attr('checked', est_jusqu_mois_courant);
            // ANd i tried this code
            radiobtnmois_courant = document.getElementById("radio_budget_cumulee_jusque_mois_courant");
            radiobtnmois_courant.checked = false;

            radiobtnfin_anneee = document.getElementById("radio_budget_cumulee_jusque_fin_anneee");
            radiobtnfin_anneee.checked = true;

        });

但单选按钮始终采用默认值。 请帮忙?

尝试<input type="radio" id="..." autocomplete="off" />

然后在你的脚本标签中尝试类似的东西

$(document).ready(function(){
    $(".myradios").prop("checked", true); // true or false
});

怎么又要重新加载漏洞页面了?更好的方法是通过 AJAX 而不是空洞页面重新加载所需的数据。您可以通过 JQuery 甚至 AngularJS

将新值归因于您的表单

对于单选按钮或复选框,您可以使用 .val() 使用值数组。

$radios.val( [ ] ); // uncheck all radios
$radios.val( [ "fin" ] ); // check the radio with value "fin"
$radios.val( [ "courant" ] ); // check the radio with value "courant"
$radios.val( [ "fin", "courant" ] ); // not useful in radio button context, but you can use this for checkboxes