【发布时间】: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>
我将a、b和c填入username、change_color和license_id文本框,但浏览器只上传username中的数据。
我试过 Chrome/Opera/Firefox,它们都是这样工作的。
谁能告诉我为什么浏览器不上传元素中的数据?
非常感谢!
【问题讨论】:
-
因为您尝试的内容不正确。如果您希望元素在表单帖子中传递,那么它们需要在表单标签中。他们不能在外面。另一种方法是使用 JS 构建数据,然后发布。
-
“谁能告诉我为什么浏览器不上传元素中的数据?” – 与邮局无法投递表格的原因相同您在发送的信旁边放置的纸张......表单是提交的内容,并且仅发送表单中的元素。这就是表单工作的方式;其他一切都没有意义。
-
知道了,谢谢@haxtbh