我正在使用 JSF-primeface 和 javascript。
这是javascript的代码。
<script>
var $element = $("select['se:type5'] option:selected").val();
alert($element);
var input = document.getElementById('se:search');
var combo = document.getElementById('se:type1');
if($element == 1)
{
input.disabled = false;
combo.disabled = true;
}
else if($element == 2)
{
input.disabled = true;
combo.disabled = false;
}
</script>
我可以使用上面的代码禁用输入框,但 onemenu 不受影响。
这是我的 JSF 代码
<p:selectOneMenu id="type5" effect="fold" onchange="disabled();"
required="true"
label="Type5" styleClass="select-option" style="border:1px solid #b5b5b5; padding-left:5px; margin-top:5px;width:298px;height:25px;" >
<f:selectItem itemLabel="Search By Skill" itemValue="1" />
<f:selectItem itemLabel="Search By Location" itemValue="2" />
</p:selectOneMenu>
<p:inputText value="#{user.latitude}" id="latitude" style="visibility: hidden" />
<h:panelGrid columns="4">
<p:inputText id="search" styleClass="inner-page-input-type"
onfocus="if(this.value=='Job title, Skills, Company, etc.') this.value='';"
onblur="if(this.value=='') this.value='Job title, Skills, Company, etc.';" type="text"
value="#{user.skill}" >
</p:inputText>
<p:selectOneMenu id="type1" value="#{user.geoLocationLatitude}" effect="fold"
required="true"
label="Type1" styleClass="select-option" style="border:1px solid #b5b5b5; padding-left:5px; margin-top:5px;width:298px;height:25px;" >
<f:selectItem itemLabel="---km---" itemValue="1" />
<f:selectItem itemLabel="Under 150km" itemValue="150" />
<f:selectItem itemLabel="Between 150km - 300km" itemValue="300" />
<f:selectItem itemLabel="Between 300km - 450km" itemValue="450" />
<f:selectItem itemLabel="Between 450km - 600km" itemValue="599" />
<f:selectItem itemLabel="Above 600km" itemValue="600" />
</p:selectOneMenu>
</h:form>