문제

I would like to call function on backingbean only if the user press the enter key. But it doesn't work. On Chrome's console, it's always returns: Uncaught TypeError: object is not a function everytime I press any button. What's wrong with the code? Thanks.

<p:inputText id="txtValue" value="#{cc.attrs.value}" onkeyup="onkeypress()">
</p:inputText>
<script type="text/javascript">
    function onkeypress() {
        if(event.keyCode==13) {
            alert("true");
        } else {
            alert("false");
        }
    }
</script>
<p:remoteCommand name="rc" actionListener="#{cc.onKeyPress}" out="count" />
도움이 되었습니까?

해결책

add parameter to your onkeypress function would fix your problem

<script type="text/javascript">
    function onkeypress(event) {
        if(event.keyCode==13) {
            alert("true");
        } else {
            alert("false");
        }
    }
</script>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top