Javascript一种形式的乘法/除法
我正在进行一个JavaScript计算,在这个计算中,我需要以一种形式对多个答案进行乘法和除法 我得到了用于#1和#2(见下文)的初始乘法,但不幸的是,我在下一节中编写了一段代码来划分两个元素,这段代码遇到了问题 基本上,我需要把答案2除以答案3 谢谢Javascript一种形式的乘法/除法,javascript,Javascript,我正在进行一个JavaScript计算,在这个计算中,我需要以一种形式对多个答案进行乘法和除法 我得到了用于#1和#2(见下文)的初始乘法,但不幸的是,我在下一节中编写了一段代码来划分两个元素,这段代码遇到了问题 基本上,我需要把答案2除以答案3 谢谢 1。 2. 3. 4 函数计算(){ var f1=parseInt(document.getElementById('f1').value); var-res=f1*12; document.getElementById
1。
2.
3.
4
函数计算(){
var f1=parseInt(document.getElementById('f1').value);
var-res=f1*12;
document.getElementById('res')。value=res;
函数计算(){
var f2=parseInt(document.getElementById('f2').value);
var res2=res/f2;
document.getElementById('res2')。value=res2;
}
}
函数定义中有一些错误
calculate
。必须为每个函数指定一个唯一的名称calculate
函数实际上包含第二个函数(缺少大括号)function calculateMul() {
var f1 = parseInt(document.getElementById('f1').value);
var res = f1 * 12;
document.getElementById('res').value = res;
}
function calculateDiv() {
var f2 = parseInt(document.getElementById('f2').value);
var res = parseInt(document.getElementById('res').value);
var res2 = res / f2;
document.getElementById('res2').value = res2;
}
。。。并在您的
onClick
事件处理程序中调用这些函数。谢谢,我认为这让我走上了正确的轨道。。。不幸的是,它仍然没有将答案从第2行和第3行中分开……我看到calculateDiv
需要res
字段中的值,所以您也必须获取该值。我已经相应地编辑了我的答案。