【发布时间】:2015-01-07 21:35:22
【问题描述】:
在我的表单中,我只想在所有字段(和单选按钮列表)都被选中时启用表单。
到目前为止,当title 字段包含以下内容时,我已经成功制作了提交按钮enable:
onkeyup="if(this.textLength != 0) {subnewtopic.disabled = false} else {subnewtopic.disabled = true}"
我的目标是仅在 所有内容 填写完毕后启用提交按钮。我该怎么做?
这是我使用jsfiddle的完整代码:
<form action="" method="post" id="subnewtopicform" />
Title:
<input type="text" name="title" onkeyup="if(this.textLength != 0) {subnewtopic.disabled = false} else {subnewtopic.disabled = true}">
<br/>
Description:
<textarea name="description"></textarea>
<br/>
Category:
<ul class="list:category categorychecklist form-no-clear" id="categorychecklist">
<li id="category-19"><label class="selectit"><input type="radio" id="in-category-19" name="category" value="19"> Animation</label></li>
<li id="category-20"><label class="selectit"><input type="radio" id="in-category-20" name="category" value="20"> Anime</label></li>
</ul>
<input type="submit" value="Submit Topic" class="button-primary" name="subnewtopic" id="subnewtopic" disabled="disabled" />
</form>
【问题讨论】:
-
看来你真的是在找人为你写验证码。有很多插件和教程。您过于简单的代码距离成为表单验证器还有很长的路要走。您还可以访问 html5 有效性属性。老实说,你应该做更多的研究