如何将 jquery 值结果传递到 Visualforce 代码中,例如:
我的jquery代码是
$j('[id$=submit]').on("click", function(){
var output = [], $jselects = $j(".container .row .span6 #form-details select"), i;
for (i=0; i < $jselects.length; i += 2)
output.push($jselects.eq(i).find("option:selected").text() +
":" + $jselects.eq(i+1).find("option:selected").text());
})
当我单击此 id 时,会生成输出值,如 b:b,s:s,a:a 这些值将作为 output
写入变量中
这是我的 Visualforce 代码
<apex:commandButton id="submit" action="{!myMethod}" value="Submit" styleClass="btn btn-primary" reRender="block">
<apex:param name="myParam" value="output"/>
</apex:commandButton>
当我按下 ID submit
时,从jquery获取输出值,并将其设置在output
的位置在<apex:param name="myParam" value="output"/>
这条线。
这里生成了输出文本,但我需要知道如何在 <apex>
内发送该值代码。
到底有没有可能……?
感谢您的回答...
最佳答案
你有三个选择
1) 创建带参数的 Action 函数。然后调用操作函数并将生成的字符串作为参数传递,就像任何其他 JavaScript 函数一样。
2) 使用 Javascript 远程处理。它允许您在方法调用的同时传递参数。但它要求方法是静态的。
3)使用隐藏<apex:hiddeninput>
field 。然后使用 javascript 设置此输入的值作为您的字符串。然后,这将通过任何常规的 apex post 事件传递给 Controller ( apex:commandButton or apex:commandLink
)
关于jquery 输出值传递给 Visualforce,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15566689/