这并不是真正的传递值。它只是在按下按钮时调用一个函数:
$(document).ready(function() {
$('form').on('submit', function(e) {
e.preventDefault(); // we don't want to submit the form
$('#piechart').each(function() { // only do this if the element is found
// clear the canvas
this.getContext('2d').clearRect(0, 0, this.width, this.height);
});
var angles = [
$('#angle1').val() || 0,
$('#angle2').val() || 0,
$('#angle3').val() || 0
];
piechart("piechart1", ["cyan", "yellow", "green"], angles);
});
});
val()
得到的值 input
元素。我们的确是 || 0
将其设置为 0
以防浏览器不理解 type="number"
并向我们发送一个空字符串。