多个单击事件无法正常工作
Multiple On click event not working correctly
我对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();
}
相关文章:
- Javascript:selenium Web驱动程序isDisplayed()不工作
- jQuery UI自动完成突然停止工作
- AngularJS UI路由器不能像ng路由器那样工作
- HTML5音频加载和播放获胜'我不能在iPad上工作
- JavaScript打印功能使日历停止工作
- Javascript.getHours()工作不正常
- 为什么这在IE中的工作方式与在Firefox中不同
- 视频HTML没有'无法在Internet Explorer 11上工作
- 扩展移相器按钮类不工作
- Firebase迁移-简单的Firebase.set没有'不再工作了——旧的还是新的
- 谷歌地图不是以HTML显示,而是在JS Fiddle上工作
- 正在尝试使用if和else添加类,但无法正常工作
- Jquery FadeIn FadeOut 只工作一次
- Foreach无法在Typescript中工作
- 另一个ajax调用中的Jquery ajax调用在for循环中没有按预期工作
- 为什么不是't窗口.恢复正常工作吗?(javascript/jquery)
- JS可以在Chrome中工作,但不能在Firefox中工作
- ajaxToolkit PopupControlExtender不工作.过时的
- HTML标记在脚本标记中工作
- javascript扫雷器floodfill算法不能正常工作