var rates = new Array();
<% for tva_rate in @tva_rates -%>
rates.push(new Array(<%= tva_rate.id %>, '<%=h tva_rate.taux %>', '<%=h tva_rate.compte_id %>' ));
<% end -%>
function tvaSelected() {
tva_id = $('journal_tva_id').getValue();
show = 1;
if (tva_id > 0){
rates.each(function(rate) {
if (rate[0] == tva_id) {
$('journal_taux').setValue(rate[1]);
$('journal_compte_tva').setValue(rate[2]);
show = 2;
}
});
}
if (show == 1) {
$('tva_taux_field').hide();
} else {
$('tva_taux_field').show();
}
}
document.observe('dom:loaded', function() {
tvaSelected();
$('journal_tva_id').observe('change', tvaSelected);
});
答案 0 :(得分:0)
我假设你做了一个完整的转换,并没有尝试同时使用jQuery和Prototype(可以这样做)。
试试这个:
var rates = new Array();
<% for tva_rate in @tva_rates -%>
rates.push(new Array(<%= tva_rate.id %>, '<%=h tva_rate.taux %>', '<%=h tva_rate.compte_id %>' ));
<% end -%>
function tvaSelected() {
tva_id = $('#journal_tva_id').val(); // use id selector and val()
show = 1;
if (tva_id > 0){
$.each(rates,function(idx,rate) {
if (rate[0] == tva_id) {
$('#journal_taux').val(rate[1]); // use id selector and val()
$('#journal_compte_tva').val(rate[2]); // use id selector and val()
show = 2;
}
});
}
if (show == 1) {
$('#tva_taux_field').hide(); // use id selector
} else {
$('#tva_taux_field').show(); // use id selector
}
}
$(function() { // use short-hand for document.ready() instead of onload event observer
tvaSelected();
$('#journal_tva_id').change(tvaSelected); //use id and set up change handler
});