跳至内容

BTEC IT 第 20 单元 - 网站设计/JavaScript/单选按钮

来自 Wikibooks,开放世界的开放书籍

选择输入(单选按钮)

<body>

<p>Choose your favourite colour!</p>

<form>
  <input type="radio" name="colour" value="blue" onclick="myFunction()">Blue<br>
  <input type="radio" name="colour" value="red" onclick="myFunction()">Red<br>
  <input type="text" id="result" size="50">
</form>

<script>
function myFunction() {
    var colour = document.forms[0];
    var txt = "";
    var i;
    for (i = 0; i < colour.length; i++) {
        if (colour[i].checked) {
            txt = txt + colour[i].value + " ";
        }
    }
    document.getElementById("result").value = txt + "...such a nice colour";
}
</script>

</body>
</html>
华夏公益教科书