简单教程
提交运行
代码编辑器:
<script> function createOrder(){ var coffee=document.forms[0].coffee; var txt=""; var i; for (i=0;i<coffee.length;i++){ if (coffee[i].checked){ txt=txt + coffee[i].value + " "; } } document.getElementById("order").value="你点了咖啡: " + txt; } </script> <p>你喜欢什么样的咖啡?</p> <form> <input type="checkbox" name="coffee" value="加冰">加冰<br> <input type="checkbox" name="coffee" value="加糖">加糖<br> <br> <input type="button" onclick="createOrder()" value="发送订单"> <br><br> <input type="text" id="order" size="50"> </form>
运行结果: