1、jsf页面中有2个单选按钮,需要在js中判断当前选中的是哪一个,可以使用如下js代码访问:
<h:form id="userForm">
<h:selectOneRadio id="loginUser">
<f:selectItem itemLabel="admin" itemValue="1"/>
<f:selectItem itemLabel="guest" itemValue="0"/>
</h:selectOneRadio>
</form>
js代码判断当前选中的单选按钮:
<script type="text/javascript">
function check() {
var selAdmin= userForm['userForm:loginUser'][0].checked;
var selGuest= userForm['userForm:loginUser'][1].checked;
if(selAdmin) {
alert("Curent selection is admin!");
}else if(selGuest) {
alert("Current selection is guest!");
}
}
</script>
2、在jsf<h:inputText/>中限制只允许输入数字:
<h:inputText id="numberInput" οnkeypress="if(event.which < 48 || event.which > 75) return false;)"/>