-2
<html>
     <h1>MB calculator</h1>

    <script type="text/javascript">
        var level = "0";
        var brawlpoints = "0";
        var brawlenergy = "0";
        var pointsmake = "0";

        function setlv() {
            level = document.forms["form"]["lv"].value;
            alert("level = " + level);
            var maxen = 95 + (level * 5);
            var exptolv = 110 + (level * 15);
        }

        function setbpbe() {
            brawlpoints = document.forms["form"]["bp"].value;
            brawlenergy = document.forms["form"]["be"].value;
            alert("points per brawl = " + brawlpoints + "; energy per brawl = " + brawlenergy);
        }

        function pointsupdate() {
            pointsmake = document.forms["form"]["p2m"].value;
            alert("you want to make " + pointsmake);
        }

    function calculatevalues() {
        var math1 = pointsmake / brawlpoints + 1;
        var math2 = brawlenergy * math1;
        var math3 = maxen * 1.75;
        var math4 = math2 / math3 + 1;
        document.write("To achieve your goal it will take you " + math1 + " brawls, this will take you " + math2 + " energy, or " + math4 + " levels, assuming a 75% refill levels you.");
    }

</script>

<form name="form">level:
    <input type="text" name="lv" value="0">
    <br>
    <input type="button" value="update level" onclick="setlv()">
    <br>points per brawl done:
    <input type="text" name="bp" value="0">
    <br>energy per brawl done:
    <input type="text" name="be" value="0">
    <br>
    <input type="button" value="update brawl energy and points" onclick="setbpbe()">
    <br>how many points you want to make:
    <input type="text" name="p2m" value="0">
    <br>
    <input type="button" value="set points you want to make" onclick="pointsupdate()">
    <br>

    <input type="button" value="calculate" onclick="calculatevalues()">

</form>

    <h1>LV calculator</h1>

</html>

把问题用粗体放在哪里,由于某种原因,按钮在按下时什么都不做......

所以,是的,在 html 中测试它,我认识的人谁知道一些 html/javascript 似乎认为表单被破坏或类似的东西......

编辑:让它工作,如果有人读到这个,如何在 javascript 中舍入?编辑:向上,而不是向下

4

2 回答 2

2

您需要maxen在全局范围内声明变量

var level = "0"; var brawlpoints = "0"; var brawlenergy = "0"; 
var pointsmake = "0";
//declare the maxen variable here
var maxen = "0";

function setlv()
{
//left of your code
于 2013-01-30T05:08:06.313 回答
0

你期待这个

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><h1>MB calculator</h1>

<script type="text/javascript">

var level = "0"; var brawlpoints = "0"; var brawlenergy = "0"; var pointsmake = "0";
var maxen;
function setlv()
{
level = document.forms["form"]["lv"].value;
alert("level = " + level);
maxen = 95+(level*5);
var exptolv = 110+(level*15);
}

function setbpbe()
{
brawlpoints = document.forms["form"]["bp"].value;
brawlenergy = document.forms["form"]["be"].value;
alert("points per brawl = " + brawlpoints + "; energy per brawl = " + brawlenergy);
}

function pointsupdate()
{
pointsmake = document.forms["form"]["p2m"].value;
alert("you want to make " + pointsmake);
}

function calculatevalues()
{
var math1 = pointsmake/brawlpoints + 1;
var math2 = brawlenergy*math1;
var math3 = maxen*1.75;
var math4 = math2/math3 + 1;

document.write("To achieve your goal it will take you " + math1 + " brawls, this will take you " + math2 + " energy, or " + math4 + " levels, assuming a 75% refill levels you.");
}

</script>

<form name="form">

level:
<input type="text" name="lv" value="0">
<br>
<input type="button" value="update level" onclick="setlv()"> 
<br>
points per brawl done:
<input type="text" name="bp" value="0">
<br>
energy per brawl done:
<input type="text" name="be" value="0">
<br>
<input type="button" value="update brawl energy and points" onclick="setbpbe()">
<br>
how many points you want to make:
<input type="text" name="p2m" value="0">
<br>
<input type="button" value="set points you want to make" onclick="pointsupdate()">
<br>
**<input type="button" value="calculate" onclick="calculatevalues()">**
</form>

<h1>LV calculator</h1>

</HTML>

maxen被声明为函数中的局部变量,setlv并且您试图在另一个函数中访问它。让它全球化

于 2013-01-30T05:09:27.450 回答