js如何判断表单中所有选项是否都填写了?包括input textarea checkbox radio等一系列的表单元素
网友回复
通过jquery的each循环,筛选出checkbox和radio单独判断是否选中
示例如下:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>BFW NEW PAGE</title> <script type="text/javascript" src="http://repo.bfw.wiki/bfwrepo/js/jquery-3.2.1.min.js"></script> </head> <body> <form id="form1" name="form1" action="" method="post"BfwOnsubmit="return check();"> <p> <input type="radio" name="item3" value="1" />是 <input type="radio" name="item3" value="2" />否 </p> <p> <input type="checkbox" name="item4" value="3" />有 <input type="checkbox" name="item4" value="4" />无 </p> <textarea name="item5"></textarea> <input type="text" name="item1" id="item1" value="" /> <input type="text" name="item2" id="item2" value="" /> <p> <input type="submit" value="提交" /> </p> ...
点击查看剩余70%
可以用jquery的serializeArray方法,代码如下:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>BFW NEW PAGE</title> <script type="text/javascript" src="http://repo.bfw.wiki/bfwrepo/js/jquery-3.2.1.min.js"></script> </head> <body> <form id="form1" name="form1" action="" method="post"BfwOnsubmit="return check();"> <p> <input type="radio" name="item3" value="1" />是 <input type="radio" name="item3" value="2" />否 </p> <p> <input type="checkbox" name="item4[]" value="3" />有 <input type="checkbox" name="item4[]" value="4" />无 </p> <input...
点击查看剩余70%