我在使用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值添加到列表中,一旦点击?
另外,我希望能够从列表中删除项目,如果可能的话
IM非常新的JavaScript,你可能会意识到
感谢
'<按钮类型= “提交” 的onclick = “的document.getElementById(” 容器 “)的appendChild(LI);”>上的例子的醇ID提交' 不是**容器** –
您有报价问题。 'container'前的引号与'onclick ='后的引号匹配,所以它结束了属性。在双引号属性中使用单引号时,或者相反。 – Barmar
你在哪里设定变量'li'? – Barmar