-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 に答える