使用 javascript 传递按钮值并使其在 xwiki 宏中可用 [英] Pass Button Value using javascript and make it usable in xwiki macro

查看:30
本文介绍了使用 javascript 传递按钮值并使其在 xwiki 宏中可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有 2 个按钮,每次单击按钮都应该调用 2 个不同的功能.我想我可以使用 Javascript 来获取值,但是如何让值在宏中可用?我试过的是这个

So I have 2 buttons and each button click is supposed to call 2 different functions. I figured I can use Javascript to get the values but how do I get the value to be usable in a macro? What I have tried is this

<script type="text/javascript">
     function getVal(value){
         #set $value=value
         alert(value)
        }
</script>

显然这是行不通的.如果没有 #set $value=value 代码,我每次点击某个东西时都会看到一个警报.

Obviously this does not work. Without the #set $value=value code, I see an alert every time I click on something.

推荐答案

您正在尝试混合两种完全不同的语言.一种在服务器上执行,一种在客户端上执行,它们之间没有直接联系.HTML 到达浏览器后,Velocity 早已停止执行,您无法从 JavaScript 返回.

You're trying to mix two completely different languages. One is executed on the server, one on the client, and there's no direct connection between them. Once the HTML reaches the browser, Velocity has long stopped executing, and you can't get back to it from JavaScript.

好吧,不是直接的.

当您必须从 JavaScript 返回到 Velocity 时,您通常会发送一个 XHR一些信息,回到服务器.您发送请求的文档将检测您发送的请求类型(使用请求参数),将执行请求的操作,并生成要发送回 JavaScript 端的响应.

When you have to go back from JavaScript to Velocity, you usually send an XHR with some piece of information, back to the server. The document where you send the request will detect what kind of request you're sending (using a request parameter), will perform the requested action, and will generate a response to be sent back to the JavaScript side.

你可以找到一个例子 在博客分类管理代码中.

You can find an example in the blog categories management code.

这篇关于使用 javascript 传递按钮值并使其在 xwiki 宏中可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆