我使用 OpenERP 7,并且有 2 个单选按钮可以更改表的值。 我创建了一个事件,它调用一个执行 sql 查询的 python 函数,之后我必须重新加载页面以显示具有新值的表。但问题是单选按钮采用默认值!所以用户只有一种选择,所以我必须在重新加载页面后设置单选按钮的默认值。这是我的 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
});
关于javascript - 加载页面后如何设置单选按钮的默认值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32563070/