嗨,我是 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>
最佳答案
您可以像这样使用required
:
<input type="radio" name="select" value="${UploadFileModel.srNum}"id="radioButton" required/>
关于javascript - 如何强制用户选择至少一个单选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49029194/