用户定义函数

时间:2016-10-27 21:32:51

标签: javascript

初学者。我一直试图让math.max在用户定义的函数中工作,但似乎无法让它工作。该函数应该从两个文本框中取两个数字,并在第三个文本框中显示两个中较大的一个。我的其余代码工作正常,但我不能让它工作,我不知道该怎么做。

function Maximum()
    // Assumes: first and second are any two numbers taken input from a Textbox
    // Results: Displays the maximum of the two input numbers in the outputDiv
    {
        var first=parseFloat(document.getElementById('first').value);
        var second=parseFloat(document.getElementById('second').value);
        maximum = math.max(first, second);
        document.getElementById('outputDiv').value = maximum;       
    }   

2 个答案:

答案 0 :(得分:3)

你需要把“数学”大写:

Math.max(first, second);

此外,在尝试显示文字时,您需要将.value替换为.innerText.innerHTML

答案 1 :(得分:1)

这是因为数学必须是资本

enter image description here

相关问题