怎样在Jquery中动态绑定RadioButtonList的选项
2015-05-21 · 百度知道合伙人官方认证企业
关注
展开全部
不要忘记jquery库的引入
//获取radiobuttonlist 选中的 text :
function GetRbtnListByEdText(radiobuttonlistid) {
return $("#" + radiobuttonlistid).find("input:checked").next("label").text();
}
//获取radiobuttonlist 选中的 value :
function GetRbtnListByEdValue(radiobuttonlistid) {
return $("#" + radiobuttonlistid).find("input:checked").attr("value");
}
//获取radiobuttonlist 选中的 索引 :
function GetRbtnListByEdIndex(radiobuttonlistid) {
var targetObj = $("#" + radiobuttonlistid + " input");
var tempThis = $("#" + radiobuttonlistid).find("input:checked")
return targetObj.index(tempThis);
}
//设置radiobuttonlist 选中的 text :
function SetRbtnListByEdText(radiobuttonlistid, _txt) {
var tempThis;
var targetObj = $("#" + radiobuttonlistid + " label");
targetObj.each(function() {
tempThis = $(this);
if (tempThis.text() == _txt) {
tempThis.prev("input").attr("checked", "checked"); //.attr("disabled", "disabled");
return;
}
})
}
//设置radiobuttonlist 选中的 value :
function SetRbtnListByEdValue(radiobuttonlistid, _val) {
$("#" + radiobuttonlistid + " input[value='" + _val + "']").attr("checked", "checked");
}
//设置radiobuttonlist 选中的 索引 :
function SetRbtnListByEdIndex(radiobuttonlistid, _selectedIndex) {
var tempThis;
var targetObj = $("#" + radiobuttonlistid + " input");
targetObj.each(function() {
tempThis = $(this);
if (targetObj.index(this) == _selectedIndex) {
tempThis.attr("checked", "checked"); return;
}
})
}
//获取radiobuttonlist 选中的 text :
function GetRbtnListByEdText(radiobuttonlistid) {
return $("#" + radiobuttonlistid).find("input:checked").next("label").text();
}
//获取radiobuttonlist 选中的 value :
function GetRbtnListByEdValue(radiobuttonlistid) {
return $("#" + radiobuttonlistid).find("input:checked").attr("value");
}
//获取radiobuttonlist 选中的 索引 :
function GetRbtnListByEdIndex(radiobuttonlistid) {
var targetObj = $("#" + radiobuttonlistid + " input");
var tempThis = $("#" + radiobuttonlistid).find("input:checked")
return targetObj.index(tempThis);
}
//设置radiobuttonlist 选中的 text :
function SetRbtnListByEdText(radiobuttonlistid, _txt) {
var tempThis;
var targetObj = $("#" + radiobuttonlistid + " label");
targetObj.each(function() {
tempThis = $(this);
if (tempThis.text() == _txt) {
tempThis.prev("input").attr("checked", "checked"); //.attr("disabled", "disabled");
return;
}
})
}
//设置radiobuttonlist 选中的 value :
function SetRbtnListByEdValue(radiobuttonlistid, _val) {
$("#" + radiobuttonlistid + " input[value='" + _val + "']").attr("checked", "checked");
}
//设置radiobuttonlist 选中的 索引 :
function SetRbtnListByEdIndex(radiobuttonlistid, _selectedIndex) {
var tempThis;
var targetObj = $("#" + radiobuttonlistid + " input");
targetObj.each(function() {
tempThis = $(this);
if (targetObj.index(this) == _selectedIndex) {
tempThis.attr("checked", "checked"); return;
}
})
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询