grails 将 div 内的文本获取到控制器

发布于 2024-12-13 19:40:49 字数 435 浏览 3 评论 0原文

我有这样的代码:

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寻梦旅人 2024-12-20 19:40:49

控制器无权访问页面本身。如果您需要在表单提交时将地址 div 的内容发送回控制器,您可以将其内容复制到隐藏的输入字段中,如下所示:

<div id="address"></div>
<input type="hidden" id="hiddenAddress" name"address" value=""/>

让设置地址内容的 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:

<div id="address"></div>
<input type="hidden" id="hiddenAddress" name"address" value=""/>

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文