示例代码,同时调用函数A和函数B:
<html>
<head>
<title>同时调用多个函数</title>
<script language="javascript">
function funA(){
alert("这是函数A")
}
function funB(){
alert("这是函数B")
}
</script>
</head>
<body>
<input type="button" value="点击调用多个函数" onClick="funA(),funB()">
</body>
</html>
也就是在调用一个函数的基础上,用逗号“,”隔开两个函数名即可。
<html><head>
<title>D.I.S. Shuttles: Passenger List</title>
<script type="text/javascript">
var MAX_NO_PASSENGERS = 10
var passengerList = new Array()
function addPassenger(){
var index = passengerList.length
if (index < MAX_NO_PASSENGERS) {
passengerList[index] = new Object()
passengerList[index].name = document.passengerForm.namebox.value
if (document.passengerForm.Child[0].checked){
passengerList[index].Child = 'Child'
}else {
passengerList[index].Child = 'Adult'
}
}else {
alert('Sorry - no more than 10 passengers allowed.')
}
document.passengerForm.namebox.value=""
document.passengerForm.namebox.focus()
}
function displayPassengers(type) {
varinner=""
if(type=='children'){
inner+="List of children currently registered as passengers:\n"+
"\n"
for(var i=0i<passengerList.lengthi++){
if(passengerList[i].Child=="Child"){
inner+=" "+passengerList[i].name+"\n"
}
}
}else if(type=='adults'){
inner+="List of adults currently registered as passengers:\n"+
"\n"
for(var i=0i<passengerList.lengthi++){
if(passengerList[i].Child=="Adult"){
inner+=" "+passengerList[i].name+"\n"
}
}
}else if(type=='people'){
inner+="List of people currently registered as passengers:\n"+
"\n"
for(var i=0i<passengerList.lengthi++){
inner+=" "+passengerList[i].name+"\n"
}
}
alert(inner)
}
</script>
</head>
<body>
<center>
<h1>D.I.S. Shuttles</h1>
<h2>Passenger List</h2>
<form action="none" name="passengerForm" onsubmit="addPassenger()return false">
<font size="+2">Passenger name:</font>
<input type="text" name="namebox" size="30" maxlength="30" /><br /><br />
<table>
<tr><td><input type="radio" name="Child" checked="checked" /><font size="+2">Child</font></td></tr>
<tr><td><input type="radio" name="Child" /><font size="+2">Adult</font></td></tr>
</table>
<br />
<input type="submit" value="Add To Passenger List" />
<br />
<h3><a href="javascript:displayPassengers('children')">
Click here to display current child passengers</a></h3>
<h3><a href="javascript:displayPassengers('adults')">
Click here to display current adult passengers</a></h3>
<h3><a href="javascript:displayPassengers('people')">
Click here to display all current passengers</a></h3>
</form>
</center>
</body>
</html>
你看看,原有代码稍微调整了下。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)