【问题标题】:[HTML]how to upload values in the <fieldset> element if the <fieldset> tag is outside of the <form> tag[HTML]如果 <fieldset> 标签在 <form> 标签之外,如何在 <fieldset> 元素中上传值
【发布时间】:2017-01-01 16:53:22
【问题描述】:

这是 HTML 代码:

<!DOCTYPE html>
<html>
    <head>
        <title>Javascript</title>
    </head>
    <body>
        <form action="/check" id="demo" method="post" name="demo">
            <input type="text" name="username" />username
            <button type="button"
                onclick="form.change_color.style.backgroundColor='#00FF00';">change
                fieldset background</button>
            <button type="button"
                onclick="activateFieldset()">activate fieldset</button>
            <input type="submit" value="submit" />
        </form>
        <fieldset form="demo" name="change_color">
            <input type="password" name="password" />password
        </fieldset>
        <fieldset form="demo" disabled="disabled" name="license" id="license">
            <input type="text" name="license_id" />license_id
        </fieldset>
        <script>
            function activateFieldset(){
                var e = document.getElementById("license");
                e.disabled = "";
            }
        </script>
    </body>
</html>

我将abc填入usernamechange_colorlicense_id文本框,但浏览器只上传username中的数据。

我试过 Chrome/Opera/Firefox,它们都是这样工作的。

谁能告诉我为什么浏览器不上传元素中的数据?

非常感谢!

【问题讨论】:

  • 因为您尝试的内容不正确。如果您希望元素在表单帖子中传递,那么它们需要在表单标签中。他们不能在外面。另一种方法是使用 JS 构建数据,然后发布。
  • “谁能告诉我为什么浏览器不上传元素中的数据?” – 与邮局无法投递表格的原因相同您在发送的信旁边放置的纸张......表单是提交的内容,并且仅发送表单中的元素。这就是表单工作的方式;其他一切都没有意义。
  • 知道了,谢谢@haxtbh

标签: html fieldset


【解决方案1】:

与一些评论者所说的不同,根据 HTML5 RFC(尽管我同意它将它们全部分组表单中会更好)。

在你的例子中,虽然你已经在字段集中很好地指定了 form 属性,但碰巧必须具有 form 属性的元素是 INPUT 的。

【讨论】:

  • 是的,Santi,你说得对,我按照你说的那样更改了我的代码,效果很好:)
  • 很好。灿烂。 :-)
猜你喜欢
  • 1970-01-01
  • 2012-04-06
  • 2022-08-02
  • 2011-01-13
  • 2011-09-25
  • 2019-12-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多