单击后禁用`< h:commandButton>`,但应该触发操作 [英] Disable `<h:commandButton>` after clicked, but action should be fired
问题描述
我的XHTML页面中有一个< h:commandButton>
。我希望单击按钮后立即禁用该按钮。然后按钮应该调用该动作。我的按钮被禁用,因为我期望,但问题是该动作没有被触发。
< h:commandButton value =Goonclick =this.disabled = trueaction =#{bean.go()}/>
I have a <h:commandButton>
in my XHTML page. I want the button to be disabled as soon as I click the button. Then the button should call the action. My button gets disabled as I expect but the problem is that the action is not fired.
<h:commandButton value="Go" onclick="this.disabled=true" action="#{bean.go()}"/>
但如果我删除了 onclick
属性,则会触发该操作。
But if I remove the onclick
attribute the action is fired.
或者,如果我使用< a4j:commandButton>
,它可以正常工作。
按照a4j按钮工作。
< a4j:commandButton value =Goonclick =this.disabled = trueaction =#{bean.go()}/>
Or if I used an <a4j:commandButton>
it works.
Following a4j button works.
<a4j:commandButton value="Go" onclick="this.disabled=true" action="#{bean.go()}"/>
点击后如何禁用< h:commandButton>
,以便行动仍然开火?
How can I disable a <h:commandButton>
after being clicked, so that the action still fires?
推荐答案
使用 setTimeout
,这样就会触发行动并且按钮将被禁用...
Use setTimeout
, that way the action will be fired and the button will be disabled...
<h:commandButton value="Go"
onclick="setTimeout('this.disabled = true;', 50);"
action="#{bean.go()}"/>
您也可以查看以下问题:如何在不阻止动作和actionListener被调用的情况下禁用h:commandButton?
You can also take a look at the following question too :How can I disable an h:commandButton without preventing the action and actionListener from being called?
这篇关于单击后禁用`< h:commandButton>`,但应该触发操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!