【问题标题】:Text field appearing with along radio buttons, where my form does not have a text input与单选按钮一起出现的文本字段,其中我的表单没有文本输入
【发布时间】:2016-08-31 00:15:06
【问题描述】:

当我运行我的代码时,我得到了这个。我没有文本输入,但是当我运行它时,我看到了文本输入和单选按钮。

<script>

function validateForm() {
    var x = document.forms["myForm"][0].value;
    if (x == null || x == "") {
        alert("i must be checked");
        return false;
    }
 var y = document.forms["myForm"][1].value;
    if (y == null || y == "") {
        alert("j must be checked");
        return false;
    }
    var z = document.forms["myForm"][2].value;
    if (z == null || z == "") {
        alert("k must be checked");
        return false;
    }
}
</script>

<body>
<form name="myForm" onsubmit="return validateForm()">
<input type="radio" name="i">click<input/>
<input type="radio"name="j">click<input/>
<input type="radio"name="k">click<input/>
<input type="submit" value="submit">
</form>
</body> 

【问题讨论】:

  • 输入标签是自闭合标签。删除所有
  • 当我检查元素时,我在样式 input、textarea、keygen、select、button、meter、progress { -webkit-writing-mode: Horizo​​ntal-tb; } 我不知道是从哪里来的。它说“用户代理样式表”
  • 这些是浏览器的默认css。要删除此 css,请参阅上面的链接 stackoverflow.com/questions/18006356/…

标签: javascript html


【解决方案1】:

input 标签内不应有任何值。

改为使用标签,如下所示:

<input type="radio" name="i" id="i1" />
<label for="i1">click</label>

【讨论】:

    【解决方案2】:

    每行第二个input标签不正确;每次你有 &lt;input type="radio"name="k"&gt;click&lt;input/&gt; 然后浏览器将其解释为

    <input type="radio"name="k" /> (automatically adds self-closing slash)
    click
    <input type="text" /> (gives the closing input tag type="text" by default)
    

    要解决此问题,您的输入应如下所示:

    <input type="radio"name="k" /> click
    

    (注意无线电输入标签内的斜线)

    【讨论】:

      【解决方案3】:

      您在每个收音机的末尾使用这些空输入标签,输入标签默认呈现为文本框

      <input/>
      

      另外,你必须用结束标签关闭你的收音机

      <input type="radio" name="i" />click
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-12-08
        • 1970-01-01
        • 1970-01-01
        • 2013-08-13
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多