简体   繁体   English

如何通过按一个按钮来调用javascript函数和ajax命令?

[英]How to call a javascript function and an ajax command by pressing one button?

so what i want is to use 1 button inside a form (because ajax requires to be in a form?) to 所以我想要的是在表单中使用1个按钮(因为ajax需要在表单中?)

1) call a javascript function, which basicly simply does some animation (like fadeout and fadein) 1)调用javascript函数,该函数基本上只是执行一些动画(例如淡出和淡入)

2) call an ajax function that updates an "information" table 2)调用ajax函数来更新“信息”表

so basicly what i want is simply clicking one button , eg "start" then the javascript does some clientside stuff like moving around objects and ajax gives me the information about those objects which are stored on the server.. 所以从本质上讲,我想要的只是单击一个按钮,例如“开始”,然后javascript执行一些客户端操作,例如在对象周围移动,而ajax为我提供了有关存储在服务器上的那些对象的信息。

our stuff looks like this : 我们的东西看起来像这样:

<h:panelGroup layout="block" id="player" class="player">
                    <h2 class="accessibility">W&uuml;rfelbereich</h2>
                    <span class="accessibility">An der Reihe ist</span><div id="currentPlayerName"><h:outputText value=" #{spiel.getSpieler_Name()}" /></div>
                    <h:commandButton id="dice" alt="W&uuml;rfel" image="resources/img/wuerfel0.png" action="#{spiel.dice()}" tabindex="4" title="W&uuml;rfel">
                        <f:ajax render=":gameinfo" onevent="animate" />
                    </h:commandButton>
                </h:panelGroup>

so gameinfo is the table with the informations retrieved from the server and called with ajax 所以gameinfo是一个表,其中包含从服务器检索并使用ajax调用的信息

and animate is our javascript function which does the animation.. 动画是我们的javascript函数,用于动画。

problem here is that animate doesnt work, once we put that ajaax command into a form tag 问题在于,一旦我们将ajaax命令放入表单标签中,动画就无法正常工作

Try this: 尝试这个:

<h:commandButton id="dice" alt="W&uuml;rfel" image="resources/img/wuerfel0.png" action="#{spiel.dice()}" tabindex="4" onclick="animate();" title="W&uuml;rfel">
    <f:ajax render=":gameinfo" />
</h:commandButton>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM