多个单击事件无法正常工作

Multiple On click event not working correctly

本文关键字:常工作 工作 单击 事件      更新时间:2023-09-26

我对onClick中的两个函数以及如何使其正常工作感到有点困惑。当只使用一个函数时它有效,但当有两个函数时,"getCustomerList()"不再有效。任何帮助将不胜感激。以下是相关代码:

.HTML:

<form name="registration" action="registration.html" onsubmit="return validateForm()" method="post">
...
...
<input type="submit" value="Submit" onClick="buttonandchecks(); getCustomerList(); return false">
</form>
<h2>Customer Attributes:</h2> 
<br>
<h3> <span id ="currentList"></span>
</h3>

JAVASCRIPT:

function buttonandchecks()
{
var x;
var output="";
var resultoutput="";
var extra=parseFloat(0);
var radio_value; 
var total=parseInt(0); 

        for(x=0;x<document.costEstimation.special.length;x++)
        {
        if(document.costEstimation.special[x].checked)
            {
             radio_value=document.costEstimation.special[x].value;
            }
        }
        radio_value=parseFloat(radio_value);

    if(document.costEstimation.AC.checked)
        {
        extra+=10;
        output=(output+" A/C");
        }
    if(document.costEstimation.WB.checked)
        {
        extra+=100;
        output=(output+" Brakes");
        }
    if(document.costEstimation.CC.checked)
        {
        extra+=20;
        output=(output+" Cruise Control");
        }
    if(document.costEstimation.BS.checked)
        {
        extra+=30;
        output=(output+" Baby Seat");
        }
total=radio_value+extra;
resultoutput=("Total: " + total.toFixed(2)+ " 'nIncluding Extras: " + output);
alert(resultoutput);
}
 function getCustomerList () {
    var customer={Text1,Lname,Add,City,StPrv,Cntry,Hphn,Wphn};
    var i=0;
    var thisList="";
    customer.Text1=document.getElementById("Text1").value;
    customer.Lname=document.getElementById("Lname").value;
    customer.Add=document.getElementById("Add").value;
    customer.City=document.getElementById("City").value;
    customer.StPrv=document.getElementById("StPrv").value;
    customer.Cntry=document.getElementById("Cntry").value;
    customer.Hphn=document.getElementById("Hphn").value;
    customer.Wphn=document.getElementById("Wphn").value;

    customerList.push(customer);
        for(i=0; i< customerList.length;i++)
        {
        var thisCustomer={Text1,Lname,Add,City,StPrv,Cntry,Hphn,Wphn};
        thisCustomer=customerList[i];
        thisList+=thisCustomer.Text1 + " , "+thisCustomer.Lname+" , "+thisCustomer.Add+" , "+thisCustomer.City+" , "+thisCustomer.StPrv+" , "+thisCustomer.Cntry+" , "+thisCustomer.Hphn+" , "+thisCustomer.Wphn;
        thisList+="<br>";
        }
    document.getElementById("currentList").innerHTML=thisList;
}
也许

您应该从buttonandchecks();方法中调用getCustomerList();。像这样:

function formSubmit() {
    buttonandchecks();
    getCustomerList();
}