简体   繁体   English

你如何从apache velocity * .vm文件中调用javascript函数?

[英]How do you invoke javascript function from an apache velocity *.vm file?

I am currently using Confluence 4.3 and I'm trying to add either an HTML button or HTML link that will invoke a javascript function. 我目前正在使用Confluence 4.3,我正在尝试添加一个HTML按钮或HTML链接,它将调用一个javascript函数。

How can this be achieved? 怎么能实现这一目标?

Specifically, there is a file called "searchpanel.vm" within Confluence which is a simple velocity template that defines criteria used to refine your confluence searches. 具体来说,Confluence中有一个名为“searchpanel.vm”的文件,它是一个简单的速度模板,用于定义用于优化汇合搜索的标准。

I wish to a button in the search panel that will invoke a javascript function. 我希望搜索面板中的一个按钮可以调用javascript函数。 How do I do this? 我该怎么做呢?

There is no special notation for writing Javascript in Velocity. 在Velocity中编写Javascript没有特殊的符号。 Just write as you normally do in any HTML file. 只需像往常一样在任何HTML文件中编写。 An example would be : 一个例子是:

    <form>
    #if ($searchVisible)
        <div id = "searchLinkContainer" >
            <a href="javascript:searchFunction()">Click here</a> to search.
        </div>  
    #end    
    </form>
    <script language="JavaScript" type="text/javascript">   
        function searchFunction () {
            //Do search
        }
    </script>

Note that if you include the tag inside a conditional statement in Velocity and it doesn't get traversed, the script will not be available in the HTML page. 请注意,如果将标记包含在Velocity中的条件语句中并且不会遍历,则HTML页面中将不提供该脚本。

Velocity is just a templating language/engine, which can print whatever you want. Velocity只是一种模板语言/引擎,它可以打印任何你想要的东西。 Just write the HTML that you would normally use regardless of the fact that you're in a .vm file. 只需编写您通常使用的HTML,无论您是否在.vm文件中。

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

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