JavaScript 循环内的 HTML

Spa*_*nce 4 html javascript

我正在尝试创建 10 个单选按钮,在 html 中用 for 循环标记为 1-10,但无法使其工作。

<html>
    <body>
      <h2 style="text-align:center">
        On a scale from 1-10, how likely are you to recommend this site to a friend or colleague?
      </h2>
        <form id="NPSform"; style= "text-align:center">
            <script>
                for (var i = 1; i <=10; i++) {
                    <input type="radio" name="scores" id="i" value="i"> i
                }
            </script>
            <input type="submit" name="mysubmit" value="Submit"/>
        </form>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

谢谢。我是 JS 新手,所以我还在学习很多东西。

Wow*_*wsk 6

用于document.write像这样输出 HTML。

document.write('<input type="radio" name="scores" id="i" value="i"> i');
Run Code Online (Sandbox Code Playgroud)

document.write('<input type="radio" name="scores" id="i" value="i"> i');
Run Code Online (Sandbox Code Playgroud)