问题描述
在.gsp文件中,我有javaScript函数
< script type =text / javascript>
函数getCurrentItemNumber(){
返回document.getElementById('item_itemNumber')。innerHTML.substr(6);
}
< / script>
和g:remoteLink我喜欢使用该函数传递参数
...
< g:remoteLink id =remove_item_buttonaction = removeItemupdate =itemBox
params =[itemNumber:getCurrentItemNumber()]> - 删除项目< / g:remoteLink>
我怎么做到这一点?
AS解决方法我可以提出以下建议:
-
将g:remoteLink更改为简单链接
p>
<a id =remove_item_buttonclass =btn small primaryonclick =removeItem();> - 删除项目</ a>
-
添加将通过AJAX提交数据的javaScript函数
$ b function removeItem(){
$ .ajax({type:'POST',
data:{'itemNumber':getCurrentItemNumber()},
url:'$ {createLink(action:'removeItem' )}',
success:function(data,textStatus){
jQuery('#itemBox')。html(data);
}});
}
in .gsp file i have javaScript function
<script type="text/javascript">
function getCurrentItemNumber(){
return document.getElementById('item_itemNumber').innerHTML.substr(6);
}
</script>
and in g:remoteLink I like to pass param using that function
something like following ...
<g:remoteLink id="remove_item_button" action="removeItem" update="itemBox"
params="[itemNumber:getCurrentItemNumber()]">- Remove Item</g:remoteLink>
How can I achieve that?
AS workaround I can suggest following
change g:remoteLink to simple link
"<"a id="remove_item_button" class="btn small primary" onclick="removeItem();">- Remove Item "<"/a>
Add javaScript function which will submit data via AJAX
function removeItem() { $.ajax({type:'POST', data:{'itemNumber':getCurrentItemNumber()}, url:'${createLink(action: 'removeItem')}', success:function (data, textStatus) { jQuery('#itemBox').html(data); }}); }
这篇关于在g:remoteLink中传递参数作为javascript函数的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!