在 .gsp 文件中我有 javaScript 函数
<script type="text/javascript">
function getCurrentItemNumber(){
return document.getElementById('item_itemNumber').innerHTML.substr(6);
}
</script>
在 g:remoteLink 中,我喜欢使用该函数传递参数
类似下面...
<g:remoteLink id="remove_item_button" action="removeItem" update="itemBox"
params="[itemNumber:getCurrentItemNumber()]">- Remove Item</g:remoteLink>
我怎样才能做到这一点?
最佳答案
我可以建议以下 AS 解决方法
将 g:remoteLink 更改为简单链接
"<"a id="remove_item_button"class="btn small primary"onclick="removeItem();">- 删除项目“<”/a>
添加javaScript函数,通过AJAX提交数据
函数 removeItem() { $.ajax({类型:'POST', 数据:{'itemNumber':getCurrentItemNumber()}, url:'${createLink(action: 'removeItem')}', 成功:功能(数据,文本状态){ jQuery('#itemBox').html(数据); }});
关于javascript - 在 g :remoteLink as result of javascript function 中传递参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10023672/