嗨,我是javascript的新手 下面是我的jsp代码,点击提交按钮我想强制用户选择至少一个无线电盒/记录。我该如何执行这项任务。
提前致谢。
<body>
<form:form id="myForm" action="actionValue" method="GET">
<input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search for Excel Names.." title="Type in a name">
<table id="myTable">
<tr class="header">
<th>Select</th>
<th>Excle SrNum</th>
<th>Excle Name</th>
<th>Uploded By</th>
<th>UplodedBy ID</th>
<th>Uplod Date and Time</th>
<th>xml Genrated ?</th>
<th>xml Genration Date and Time</th>
<th>Action</th>
</tr>
<c:forEach items="${UploadFileModel}" var="UploadFileModel">
<tr>
<td><input type="radio" name="select" value= "${UploadFileModel.srNum}" id="radioButton"/></td>
<td>${UploadFileModel.excleSrNum}</td>
<td>${UploadFileModel.fileName}</td>
<td>${UploadFileModel.uplodedByName}</td>
<td>${UploadFileModel.uplodedByNum}</td>
<td><fmt:formatDate value="${UploadFileModel.uplodeDateTime.time}" type="date" pattern="yyyy-MM-dd HH:mm:ss"/></td>
<td>${UploadFileModel.xmlGenrated}</td>
<td><fmt:formatDate value="${UploadFileModel.xmlGenrationDateTime}" type="date" pattern="yyyy-MM-dd HH:mm:ss"/></td>
<td><input type = "submit" name="GenrateXML" value="Genrate XML" id="xmlButton" />
<input type = "submit" name="DeleteRecord" value="Delete Record" id="Delete Button"/>
</td>
</tr>
</c:forEach>
</table>
<!-- ********* Below code showing error message from controller if any***********..... -->
<form:errors path="*" />
<c:if test="${not empty message}">
<h4 style="font-style: italic; color: red;">${message}</h4>
</c:if>
<!-- ********* Above code showing error message from controller if any************..... -->
</form:form>
</body>
答案 0 :(得分:2)
您可以像这样使用required
:
<input type="radio" name="select" value="${UploadFileModel.srNum}"id="radioButton" required/>
答案 1 :(得分:0)
对于javascript使用下面的代码
if ($("input[type=radio]:checked").length > 0) {
// Do your stuff here
}
检查单选按钮长度并进行操作。
答案 2 :(得分:0)