【发布时间】:2010-03-31 06:51:42
【问题描述】:
我需要获取使用 jQuery 选择的单选按钮选项的值。我正在使用以下代码,但 Firebug 中未定义“str”:
//handling Feed vs. Ingredient RadioButton
$('[id$=rdoCheck]').change(function() {
str = $("input[name='rdoCheck']:checked").val();
//ingredients
if (str == "ing")
{ $('[id$="lblDescription"]').text("Ingredient") }
//finished feed
else if (str == "ffc")
{ $('[id$="lblDescription"]').text("Finished") }
});
【问题讨论】:
-
可以显示对应的HTML代码吗?
-
名称属性选择器中不需要引号。
$("input[name=rdoCheck]:checked")就足够了。 -
用
var声明你的变量!!!天哪,这在 StackOverflow 上就像每天发生。
标签: jquery radio-button