Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 多个按钮未从不同阵列中选择_Javascript_Html - Fatal编程技术网

Javascript 多个按钮未从不同阵列中选择

Javascript 多个按钮未从不同阵列中选择,javascript,html,Javascript,Html,我正在尝试构建一系列随机生成器。我只对代码使用HTML和javaScript。当我运行代码时,它会正确显示。但是,我选择哪个按钮并不重要,它是从同一个数组中选择的。有人能帮忙吗?代码如下 <!DOCTYPE html> <html> <head> <title> Random Table Generators </title> </head> <body> <h1&

我正在尝试构建一系列随机生成器。我只对代码使用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>

随机表生成器
随机疯狂效应

函数getValue() { var shortTermMad=[“角色撤退到他或她的头脑中并变得瘫痪。如果角色受到任何伤害,效果将终止。”,“角色变得无能力,并在持续时间内尖叫、大笑或哭泣。”,“角色变得害怕,必须每轮使用他们的行动和移动来逃离恐惧源。”,“角色”er开始胡言乱语,无法正常说话或施法。“,“角色必须在每一轮中使用他们的动作攻击最近的生物。”,“角色经历了生动的幻觉,在能力检查中处于劣势。”,“角色经历了一种强烈的欲望,想要吃一些奇怪的东西,如污垢、黏液或内脏。”,“角色被惊呆了。”,“角色失去了知觉。”] var randomValue=shortermmad[Math.floor(Math.random()* 短期(长度)]; //警报(随机值); document.getElementById(“sMessage”).innerHTML=randomValue; } 函数getValue2() { 长期风险价值=[“角色感到必须反复重复特定的活动,如洗手、触摸物品、祈祷或数硬币。”,“角色经历了生动的幻觉,在能力检查方面处于劣势。”,“角色患有极端偏执症。角色在智慧和魅力检查方面处于劣势。”角色对某事(通常是疯狂的根源)有强烈的反感,好像受到反感/同情咒语的反感效果的影响。“角色经历了一个强大的错觉。选择一种药剂。角色想象他或她受到了它的影响。”,“角色会依附于一个“幸运符”例如一个人或一个物体,并且在攻击掷骰、能力检查和距离它超过30英尺时的豁免掷骰上处于劣势。”,“角色失明(25%)或耳聋(75%)“,”角色经历无法控制的颤抖或抽搐,这对攻击掷骰、能力检查和涉及力量或灵巧的豁免掷骰造成不利影响。“,”角色患有部分健忘症。角色知道自己是谁,保留种族特征和阶级特征,但不认识其他人或rem消除疯狂生效前发生的任何事情。',“每当角色受到伤害时,他或她必须在DC 15智慧豁免检定中成功,或者受到影响,就好像他或她在对混乱法术的豁免检定中失败一样。混乱效果持续1分钟。',“角色失去说话能力。',“角色摔倒。”无意识。任何程度的碰撞或伤害都无法唤醒角色。“] var randomValue2=longTermMad[Math.floor(Math.random()*longTermMad.length)]; //警报(随机值2); document.getElementById(“lMessage”).innerHTML=randomValue2; }
您不应该在第二个按钮上使用
onClick=“getValue2()”


在我看来,这似乎是一个常规的打字错误。

两个按钮都在调用同一个函数,
getValue
,您应该让第二个按钮调用
getValue2
——或者,更好的是,重命名您的函数,以便它们代表它们所做的事情,这样以后就不会发生这种混淆。例如,一个选项是
disp>layShortTerm()
。投票以打字错误结束感谢,我的一生都找不到它。我想这可能是一个打字错误,但就是看不见。