Jquery-ajax解析xml并设置radiobutton

发布于 2024-09-03 10:28:25 字数 220 浏览 1 评论 0原文

我有一个带有一些单选按钮的表单,如下所示:

<input type="radio" name="leva" value="a"><input type="radio" name="leva" value="b">

使用ajax post方法我收到单选按钮的值。 问题是如何设置正确的单选值来检查?

提前致谢 再见 h.

I've a form with some radio button like this:

<input type="radio" name="leva" value="a"><input type="radio" name="leva" value="b">

with ajax post method I receive value of the radio.
The question is how can I set correct radio value to checked?

thanks in advance
ciao
h.

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

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

发布评论

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

评论(1

寂寞美少年 2024-09-10 10:28:26

您只需要使用 属性等于选择器 作为值找到正确的按钮,然后使用 .attr()checked 属性a>,像这样:

$("input:radio[name='leva'][value='"+ returnedValue +"']").attr('checked', true);

浏览器将处理取消选择其他选项的情况,因为它是一个单选按钮,如果没有找到带有 value 的按钮...好吧,就像所有 jQuery 选择器一样,它只是不会有任何效果,这通常是我们想要的。

You just need to find the right button using an attribute equals selector for the value, then set checked attribute using .attr(), like this:

$("input:radio[name='leva'][value='"+ returnedValue +"']").attr('checked', true);

The browser will handle un-selecting the other options since it's a radio button, and if no button is found with the value...well, like all jQuery selectors, it just won't have any effect, which is usually what's desired.

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