首页 > 解决方案 > 多个按钮未从不同的数组中选择

问题描述

我正在尝试构建一系列随机生成器。我只对代码使用 HTML 和 javaScript。当我运行代码时,它显示正确。但是,我选择哪个按钮并不重要,它是从同一个数组中选择的。有人可以帮忙吗?代码如下。

<!DOCTYPE html>
<html>
<head>

    <title>
        Random Table Generators
    </title>
</head>
<body>
    <h1>Random Madness Effects</h1>

    <div>
        <input type="button" id="btnSearch" value="Short Term Madness" 
onClick="getValue();" />
    <input type="button" id="btnSearch" value="Long Term Madness" onClick="getValue();" />
    </div>
    <p id="sMessage" ></p><p id="lMessage"></p>

    </body>

<footer>
    <script>

        function getValue()
        {
            var shortTermMad = ['The character retreats into his or her mind and becomes paralyzed. The effect ends if the character takes any damage.', 'The character becomes incapacitated and spends the duration screaming, laughing, or weeping.', 'The character becomes frightened and must use their action and movement each round to flee from the source of fear.', 'The character begins babbling and is incapable of normal speech or spellcasting.', 'The character must use their action each round to attack the nearest creature.', 'The character experiences vivid hallucinations and has disadvantage on ability checks.', 'The character experiences an overpowering urge to eat something strange such as dirt, slime, or offal.', 'The character is stunned.', 'The character falls unconscious.']

        var randomValue = shortTermMad[Math.floor(Math.random() * 
shortTermMad.length)];

        //alert(randomValue);
        document.getElementById("sMessage").innerHTML=randomValue;
        }

        function getValue2()
        {
        var longTermMad = ['The character feels compelled to repeat a specific activity over and over, such as washing hands, touching things, praying, or counting coins.', 'The character experiences vivid hallucinations and has disadvantage on Ability Checks.', 'The character suffers extreme paranoia. The character has disadvantage on Wisdom and Charisma Checks.', 'The character regards something (usually the source of madness) with intense revulsion, as if affected by the antipathy effect of the Antipathy/Sympathy spell.', 'The character experiences a powerful delusion. Choose a potion. The character imagines that he or she is under its effects.', 'The character becomes attached to a “lucky charm,” such as a person or an object, and has disadvantage on Attack rolls, Ability Checks, and Saving Throws while more than 30 feet from it.', 'The character is Blinded (25%) or Deafened (75%).', 'The character experiences uncontrollable tremors or tics, which impose disadvantage on Attack rolls, Ability Checks, and Saving Throws that involve Strength or Dexterity.', 'The character suffers from partial amnesia. The character knows who he or she is and retains Racial Traits and Class Features, but doesn’t recognize other people or remember anything that happened before the madness took effect.', 'Whenever the character takes damage, he or she must succeed on a DC 15 Wisdom saving throw or be affected as though he or she failed a saving throw against the Confusion spell. The Confusion effect lasts for 1 minute.', 'The character loses the ability to speak.', 'The character falls Unconscious. No amount of jostling or damage can wake the character.']

        var randomValue2 = longTermMad[Math.floor(Math.random() * longTermMad.length)];

        //alert(randomValue2);
        document.getElementById("lMessage").innerHTML=randomValue2;
    }

    </script>
</footer>

</html>

标签: javascripthtml

解决方案


你不应该onClick="getValue2()"在第二个按钮上使用吗?

在我看来,这就像一个普通的错字。


推荐阅读