Javascript Primefaces 运行 java 脚本 onComplete/onClick

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14706432/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 17:41:03  来源:igfitidea点击:

Primefaces run java script onComplete/onClick

javascriptjsfprimefaces

提问by unzoomed

I have a p:command button as shown below.

我有 ap:command 按钮,如下所示。

<p:commandButton id="settings" ajax="false" onComplete="window.alert('sometext');"      value="#{messages.settings}"
styleClass="cancelButton" style="font-family: sans-serif, Arial, Helvetica, Geneva; font-size: 10pt; width: 90px;" /></td>

I want this button to run a java-script onComplete or onClick but I can not get any of them to work. I actually want it to open a popup but here I have tried with an easier script to just do an alert. But this does not work either. Nothing happens at all.

我想让这个按钮运行一个 onComplete 或 onClick 的 java 脚本,但我无法让它们中的任何一个工作。我实际上希望它打开一个弹出窗口,但在这里我尝试使用更简单的脚本来发出警报。但这也不起作用。什么都不会发生。

Can anyone help me?

谁能帮我?

回答by Daniel

First : there is no capitals in onxxx(where xxx is start/ complete/ success)

第一:里面没有大写字母onxxx(xxx是 开始/完成/成功

Since you set ajax="false"your button won't do any ajax , which means that onstart/ oncomplete/ onsuccesswon't be triggered at all

既然你设置ajax="false"你的按钮将不会有任何阿贾克斯,这意味着onstart/ oncomplete/onsuccess将无法在所有的触发

Use onclick="alert('wow')"

onclick="alert('wow')"

If you will remove the ajax="false"you will be able to use oncomplete="alert('wow')"

如果你将删除ajax="false"你将能够使用oncomplete="alert('wow')"