如何在 ZK 中调用 javascript 函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13854326/
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-10-26 19:58:08  来源:igfitidea点击:

How to call javascript function in ZK

javascriptzk

提问by Narayan Subedi

In ZK framework, inside zul file i want to call javascript function but it does not happens.

在 ZK 框架中,在 zul 文件中,我想调用 javascript 函数,但它没有发生。

<a label="Click" onClick="popUp();">

I have that popUp() function also. But when I click on

我也有那个 popUp() 函数。但是当我点击

<script type="text/javascript">
    function createPopUp(url)
    {
        var w = 600;
        var h = 500;
        var left = (screen.width/2)-(w/2);
        var top = (screen.height/2)-(h/2);
        window.open(url,'name','scrollbars=yes,width='+w+', height='+h+', top='+top+', left='+left);
    }
</script>

But when I click on that link it dispalys following error:

但是当我单击该链接时,它会显示以下错误:

Sourced file: inline evaluation of: `` popUp();'' : 
Command not found: popUp() : at Line: 13 : 
in file: inline evaluation of: `` popUp();'' : popUp ( ) 

采纳答案by asyard

As an alternative, if you want to achieve this in java, rather than .zul file, you can use

作为替代方案,如果您想在 java 而不是 .zul 文件中实现这一点,您可以使用

label.setWidgetListener(Events.ON_CLICK, "popUp();");

as indicated herewith javadoc

如此使用javadoc 所示

回答by Narayan Subedi

To solve this problem I found below way:

为了解决这个问题,我找到了以下方法:

<a label="Click" xmlns:w="http://www.zkoss.org/2005/zk/client" w:onClick="createPopUp('http://www.facebook.com/prabhatsubedi');"/>