使用 Jquery 处理 Spring MVC 表单:单选按钮

发布于 2024-08-06 11:45:51 字数 873 浏览 5 评论 0原文

有人使用 Spring MVC 和 Jquery 吗?

我在使用 Jquery 处理 Spring MVC 标签时遇到了一个奇怪的问题。

我使用 spring MVC 的标签来绑定单选按钮。

<form:form name="Form1" method="post" action="Form1.do" commandName="Page1Command">

<form:radiobutton path="group" value="TTSE" id="DevGroup_TTSE"  />
<form:radiobutton path="group" value="TTDE" id="DevGroup_TTDE"  />

现在,对于一些验证任务,我使用了 Jquery 选择器,如下所示:

$("form:radiobutton").click(function() { 
   alert($(this).attr("id"));
 });

现在令人惊讶的是,我收到了带有值“Page1Command”的警报,这是我给出的名称 命令名。

然后我尝试使用 id 选择器来创建一个特定的单选按钮。

$("#DevGroup_TTDE").click(function(){
     alert($(this).attr("id"));
})

现在我得到了正确的值“DevGroup_TTDE”

这出了什么问题?我们不能用 Jquery 正确处理 spring MVC 标签吗?

顺便说一句,我对这两种技术都是新手!

有什么帮助吗?

问候。

has any one using Spring MVC with Jquery!

i have got a strange problem when handling Spring MVC tags with Jquery.

i used tags of spring MVC to get radiobuttons binded.

<form:form name="Form1" method="post" action="Form1.do" commandName="Page1Command">

<form:radiobutton path="group" value="TTSE" id="DevGroup_TTSE"  />
<form:radiobutton path="group" value="TTDE" id="DevGroup_TTDE"  />

now for some validation task i used Jquery selector as follows:

$("form:radiobutton").click(function() { 
   alert($(this).attr("id"));
 });

now surprisingly i am getting alert with value "Page1Command" the name i have give for
commandName.

then i tried with id selector for one perticular radiobutton.

$("#DevGroup_TTDE").click(function(){
     alert($(this).attr("id"));
})

now i am getting the correct value as "DevGroup_TTDE"

what went wrong with this? can't we handle spring MVC tags with Jquery properly.

BTW, i am new to both technologies!

any help?

regards.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

蘑菇王子 2024-08-13 11:45:51

form: 标签在服务器端解释,并在客户端生成常规 HTML 标签。由于 jQuery 仅在客户端运行,因此它无法使用以下形式查找内容:标签。尝试运行该页面并查看 HTML 源代码,然后根据您在其中看到的内容建立 jQuery 选择器。

The form: tags are interpreted on the server side, and generate regular HTML tags on the client side. Since jQuery is only running on the client side, it won't be able to find things using the form: tags. Try running the page and viewing the HTML source, then base your jQuery selectors on what you see there.

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