我在使用appendChild函数时遇到问题...
这是我的代码
<!DOCTYPE html>
<html>
<body>
<form oninput="x.value=((parseFloat(winning_number.value)%(parseFloat(total_key_value.value)*100*2))/(parseFloat(total_key_value.value)*2)).toFixed(2)">
<input type="number" id="winning_number" value="" placeholder="Winning Number"> ~
<input type="number" id="total_key_value" value="" placeholder = "Total (Keys)">
= <output name="x" for="winning_number total_key_value"></output>%
</form>
<button type="submit" onclick="document.getElementById("container").appendChild(li);">Submit</button>
<ol id="list"></ol>
</body>
</html>
我输入2个数字,它会使用公式计算结果。
如何制作一个按钮,单击后会将 x 值添加到列表中?
另外,如果可能的话,我希望能够从列表中删除项目
正如你所知,我对 javascript 很陌生
谢谢
最佳答案
我不确定你在这里想做什么,但快速浏览了一下,我发现你的 onclick 中有一个拼写错误。
onclick="document.getElementById("container").appendChild(li);"
您的撇号有问题。如果您使用的是“”,那么内部的必须是“\”或简单地输入“”
这会起作用:
onclick="document.getElementById('container').appendChild(li);"
关于javascript - 如何通过单击按钮向列表添加值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36707321/