grails 将 div 内的文本获取到控制器
我有这样的代码:
<g:form controller="IMI" action="action1">
<g:textField name="area" value="${myValue}" />
<br><br>
<div id="address"></div>
<g:submitButton name="update" value="Calcule IMI" />
在控制器中可以通过以下方式访问文本视图中引入的文本:
params.area
但是,我有一个 js 函数,它将用文本填充我的“地址”div。我也想在控制器中检索该文本。
问题:我如何在控制器中访问 div“地址”内的文本?
I have this code:
<g:form controller="IMI" action="action1">
<g:textField name="area" value="${myValue}" />
<br><br>
<div id="address"></div>
<g:submitButton name="update" value="Calcule IMI" />
The introduced text in the textview is accessible in controller via:
params.area
However, i have a js function that will fill my 'address' div with text. I would like to retrieve that text in the controller also.
Question:How can i have access in the controller to the text inside div "address" ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
控制器无权访问页面本身。如果您需要在表单提交时将地址 div 的内容发送回控制器,您可以将其内容复制到隐藏的输入字段中,如下所示:
让设置地址内容的 JS 也设置该值的hiddenAddress 相同。另一个想法是使用类似 jQuery 的东西来捕获表单提交,抓取 div 的内容并将其附加到表单提交中(本质上实现相同的事情,只是使用更多的 JS 代码)
The controller doesn't have any access to the page itself. If you need to send the contents of the address div back to the controller upon form submission, you could duplicate the contents of it in a hidden input field, like such:
And have your JS that sets the contents of the address also set the value of hiddenAddress to the same. Another idea is to use something like jQuery to catch the form submission, grab the contents of the div and append it to the form submission (essentially achieving the same thing, just using more JS code)