Javascript复选框功能未按预期工作

时间:2018-03-20 18:20:06

标签: javascript function

出于某种原因,当我只有一个复选框项时,金额不会显示。但是,如果我有两个或更多复选框项,则金额将显示在需要的位置。以下是我的代码,请帮忙!

function checkOnly(stayChecked) {
var lInputs = document.getElementsByTagName("input");
var fieldNum = 0;
for(var i = 0; i < lInputs.length; i++) {
    if(lInputs[i].type == "checkbox") {
        if ( stayChecked != lInputs[i].name ) {
            lInputs[i].checked = false;
        } else {
          //Set the selected cost for this registration
            var selectedCost = document.getElementById( "tfa_2201[" + fieldNum + "]");
            var setSelectedCost = document.getElementById( "tfa_2202" );
            setSelectedCost.value = selectedCost.value;
          //Set the selected price for this registration
            var selectedPrice = document.getElementById( "tfa_2197[" + fieldNum + "]" );
            var setSelectedPrice = document.getElementById( "tfa_2204");
            setSelectedPrice.value = selectedPrice.value;
          //Set the amount due field
            var selectedPrice = document.getElementById( "tfa_2197[" + fieldNum + "]" );    // amount for class
            var setSelectedPrice = document.getElementById( "tfa_2532");                    // amount due
            setSelectedPrice.value = selectedPrice.value;
        }
        fieldNum++;

    }
}

0 个答案:

没有答案