Javascript 当h:inputText没有值时禁用h:commandButton
我有两个h:inputText文本框和一个h:commandButton。如果两个文本框中都没有值,如何禁用按钮?另外,如果其中一个文本框中有值,如何禁用另一个文本框。请在下面找到我的示例代码:Javascript 当h:inputText没有值时禁用h:commandButton,javascript,jsf-1.2,Javascript,Jsf 1.2,我有两个h:inputText文本框和一个h:commandButton。如果两个文本框中都没有值,如何禁用按钮?另外,如果其中一个文本框中有值,如何禁用另一个文本框。请在下面找到我的示例代码: <h:form id="myForm"> <h:inputText id="first" value=#{myBean.first}></h:inputText> <h:inputText id="second" value=#{myBe
<h:form id="myForm">
<h:inputText id="first" value=#{myBean.first}></h:inputText>
<h:inputText id="second" value=#{myBean.second}></h:inputText>
<h:commandButton id="submit" action="#{myBean.submit}" value="Submit"/>
</h:form>
这里的问题是它工作正常,但我必须单击一次外部以启用/禁用按钮。是否在将数据输入其中一个文本框时,按钮会自动启用,而另一个文本框会被禁用?使用onchange事件而不是keyuponload或直接在commandButton标记中保留按钮 disabled=真。
将onchange或onblur方法实现为inpuText,并将样式设置为commandButton disable='false'您能为myForm发布生成的HTML吗?
document.getElementById("myForm:first").onkeyup = function() {
if (this.value.length > 0) {
document.getElementById("myForm:second").disabled = true;
document.getElementById("myForm:submit").disabled = false;
} else {
document.getElementById("myForm:second").disabled = false;
document.getElementById("myForm:submit").disabled = true;
}
};
document.getElementById("myForm:second").onkeyup = function() {
if (this.value.length > 0) {
document.getElementById("myForm:first").disabled = true;
document.getElementById("myForm:submit").disabled = false;
} else {
document.getElementById("myForm:first").disabled = false;
document.getElementById("myForm:submit").disabled = true;
}
};