[英]JSF Browse button - radio button check
我正在使用战斧库中的项目浏览按钮。
浏览按钮代码。
<td><t:inputFileUpload id="file" value="#{sampleService.file}"
valueChangeListener="#{sampleService.file}" /></td>
单选按钮代码
<td><input type="radio" /> This is compulsory</td>
我要在此处进行验证,如果用户尚未检查单选按钮,则应显示一条消息以检查单选按钮。
谢谢你的帮助
给单选按钮指定一个固定的id
并在文件字段的onclick
中检查其checked
状态,如果它为false
,则显示一条消息(警告?),然后返回false
来阻止浏览按钮。
例如
<t:inputFileUpload id="file" value="#{sampleService.file}" valueChangeListener="#{sampleService.file}"
onclick="if (!document.getElementById('compulsory').checked) { alert('Please check radio button'); return false; }"
/>
<input type="radio" id="compulsory" /> This is compulsory
您也可以将其包装在JS函数中:
function checkCompulsory() {
if (!document.getElementById('compulsory').checked) {
alert('Please check radio button');
return false;
} else {
return true;
}
}
同
<t:inputFileUpload id="file" value="#{sampleService.file}" valueChangeListener="#{sampleService.file}"
onclick="return checkCompulsory()"
/>
<input type="radio" id="compulsory" /> This is compulsory
如果您在这里搜索,您会发现它,但您的兴趣是
var radios = document.getElementsByTagName('input');
var value;
for (var i = 0; i < radios.length; i++) {
if (radios[i].type === 'radio'){
if(radios[i].checked) {
// get value, set checked flag or do whatever you need to
value = radios[i].value;
} else {
alert('This is compulsory')
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.