【发布时间】:2016-07-01 06:05:05
【问题描述】:
我有一个自己的 TagLib 和一个名为 boxLink 的标签来生成远程链接并打开一个模态:
Closure boxLink = { attrs, body ->
Integer modalId = OwnUtil.getRandomNumber(1000)
Map params = attrs.params ? attrs.params : [:]
params.put('modalId', modalId)
Map linkParams = params
out << '<a href="#" class="modalBoxLink ' + attrs.class
if (attrs.title)
out << ' tooltipSpan" title="' + attrs.title
out << '" onclick="'
out << remoteFunction(controller: attrs.controller, action: attrs.action, onLoading: attrs.onClick + ';loadingSpinner()', onComplete: 'removeSpinner()',
onSuccess: 'viewModalBox(data,' + modalId + ');initForm();', onFailure: 'errorAlert();', params: linkParams)
out << '">'
out << body()
out << '</a>'
}
在某些情况下,我需要读取表单元素的值以将其放入 AJAX 请求的数据中,所以我尝试了这个
if(attrs.elementid){
def elParam = attrs.elementid
if(attrs.elementname)
elParam = attrs.elementname
linkParams.put(elParam,"document.getElementById('${attrs.elementid}').value")
}
这会生成这个ajax请求的数据值
data:{'modalId': '357','application': 'document.getElementById('elementid').value'}
如何通过获取 HTML 元素的值来设置 ajax 请求的数据属性?
【问题讨论】:
标签: javascript jquery ajax grails