是否可以通过javascript中的单击调用两个函数。单独的函数实现编码就是这样。
<input type="checkbox" id="3" class="radio" value="3" onchange="checkbox(this.id)" name="c1"></input>
,第二个是
<button type="button" onclick="calculation()">Submit</button>
我想在单击时调用这两个函数。这可能吗?
第一个功能编码就像这样
function checkbox(clicked_id)
{
var checkbox = document.getElementById(clicked_id);
if(checkbox.checked==true)
{
// coordintaes for routes
//var m=65;
// Get coordinates of route and display it
for(m=1;m<=36;m++){
//alert(m);
$.ajax({
url: "route_query4district.php?id="+m,
dataType: 'json',
success: function (msg1)
{
xarray1 = new Array();
yarray1 = new Array();
color1 = new Array();
js_data1 = eval(msg1);
// alert(js_data1);
var k1=0;
for(j1=0;j1<js_data1.length;j1+=3){
xarray1[k1] = js_data1[j1];
yarray1[k1] = js_data1[j1+1];
color1[m] = js_data1[j1+2];
k1++;
}
alert(color1[1]);
var flightPlanCoordinates = new Array();
for(i=0;i<xarray1.length;i++){
flightPlanCoordinates[i] = new google.maps.LatLng(yarray1[i], xarray1[i]);
}
var contentString = '<div id="content">';
var infowindow = new google.maps.InfoWindow({
content: contentString
});
var mid_color=67+((parseInt(checkbox.value)));
var last_color=36+((parseInt(checkbox.value)));
var line_color=color1[m];
var stroke_color=line_color.toString();
var linee_color=color1;
var strokee_color=linee_color.toString();
flightPath[m] = new google.maps.Polygon({
path: flightPlanCoordinates,
strokeColor: stroke_color,
fillColor: line_color,
strokeOpacity: 1.0,
strokeWeight: 4
});
flightPath[m].setMap(map);
google.maps.event.addListener(flightPath, 'click', function() {
infowindow.open(map,flightPath);
});
}
});
}
} // if checkbox is checked
和第二功能编码是
function calculation(){
var laastyear= document.getElementById("LasttYear").value;
var firstyeaar= document.getElementById("FfYear").value;
var projecteedyear= document.getElementById("ProjectedYear").value;
// alert("hh");
$.ajax({
url: "test_dictrict_projections_folrmula.php?LastYear="+laastyear+"&FYEAR="+firstyeaar+"&ProjectYear="+projecteedyear,
});
};
};
答案 0 :(得分:0)
是的,onclick只是一个javascript部分。你可以将整个功能放在那里。这样的事情应该有效:
onclick="calculation();checkbox(this.id);"
答案 1 :(得分:0)
我不想听起来像个笨蛋..但是你试着在标签上添加两个事件监听器吗?
类似的东西:
<!DOCTYPE html>
<html lang = 'es'>
<head>
<title> MY TEST </title>
</head>
<body>
<input type = 'button' value = 'Lets DO IT!' id = 'button'>
<script>
var inputButton = document.getElementById('button');
inputButton.addEventListener('click', show1);
inputButton.addEventListener('click', show2);
function show1(){
alert('Message 1');
}
function show2(){
alert('Message 2');
}
</script>
</body>
</html>