Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/442.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 当h:inputText没有值时禁用h:commandButton_Javascript_Jsf 1.2 - Fatal编程技术网

Javascript 当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:inputText文本框和一个h:commandButton。如果两个文本框中都没有值,如何禁用按钮?另外,如果其中一个文本框中有值,如何禁用另一个文本框。请在下面找到我的示例代码:

<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事件而不是keyup

onload或直接在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;
    }
};