jQuery-ajax解析xml并设置单选按钮 [英] Jquery-ajax parse xml and set radiobutton

查看:100
本文介绍了jQuery-ajax解析xml并设置单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

用ajax post方法

我收到收音机的值. 问题是如何设置要检查的正确单选值?

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

先谢谢了 再见 h.

推荐答案

您只需要使用属性等于选择器作为值,然后使用 .attr() ,就像这样:

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);

由于是单选按钮,浏览器将处理其他选项的取消选择,并且如果value没有找到任何按钮...那么,像所有jQuery选择器一样,它将没有任何作用,这通常是需要的.

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.

这篇关于jQuery-ajax解析xml并设置单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆