我正在尝试构建一系列随机生成器。我只使用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>
答案 0 :(得分:1)
您不应该在第二个按钮上使用onClick="getValue2()"
。
在我看来像是普通的错字。