jQuery中的RadioButton,input,CheckBox取值赋值实现代码
前端  /  管理员 发布于 2年前   233
1、jquery 获取单选组radio 2、jquery获取radiobutton的下一个值 3、jquery 获取input的值 4、jquery判断多选框checkbox JQUERY如何获取text,areatext,radio,checkbox,select值? 控制表单元素: 单选组radio: $("input[@type=radio]").attr("checked",'2');//设置value=2的项目为当前选中项 下拉框select: $("#sel").attr("value",'-sel3');//设置value=-sel3的项目为当前选中项 jQuery 获取和设置select下拉框的值文章分类:.net编程 获取Select : 获取select选中的 value: 获取select选中的索引: 设置select: 设置select 选中的value: 设置select 选中的text: 设置select option项: 清空 Select:
$("input[name='name']:checked").val();
$("input[name='name']:checked").next().text()
$("input[name='name']:checked").val()
$('#id').val()
$("#id:checkbox").attr("checked")
取值 $("#id").attr("value");
赋值则是在text()、val()里面直接给值
$("input").val();
$("textarea").text();
$("select").val();
文本框,文本区域:$("#txt").attr("value",'');//清空内容
$("#txt").attr("value",'11');//填充内容
多选框checkbox: $("#chk1").attr("checked",'');//不打勾
$("#chk2").attr("checked",true);//打勾
if($("#chk1").attr('checked')==undefined) //判断是否已经打勾
$("").appendTo("#sel")//添加下拉框的option
$("#sel").empty();//清空下拉框
获取select 选中的 text :
$("#ddlRegType").find("option:selected").text();
$("#ddlRegType ").val();
$("#ddlRegType ").get(0).selectedIndex;
设置select 选中的索引:
$("#ddlRegType ").get(0).selectedIndex=index;//index为索引值
$("#ddlRegType ").attr("value","Normal“);
$("#ddlRegType ").val("Normal");
$("#ddlRegType ").get(0).value = value;
var count=$("#ddlRegType option").length;
for(var i=0;i
{
$("#ddlRegType ").get(0).options[i].selected = true;
break;
}
}
$("#select_id option[text='jQuery']").attr("selected", true);
$("#select_id").append(""); //添加一项option
$("#select_id").prepend(""); //在前面插入一项option
$("#select_id option:last").remove(); //删除索引值最大的Option
$("#select_id option[index='0']").remove();//删除索引值为0的Option
$("#select_id option[value='3']").remove(); //删除值为3的Option
$("#select_id option[text='4']").remove(); //删除TEXT值为4的Option
$("#ddlRegType ").empty(); 您可能感兴趣的文章:
博主 在
2023年国务院办公厅春节放假通知:1月21日起休7天中评论 @ xiaoB 你只管努力,剩下的叫给天意;天若有情天亦老,..xiaoB 在
2023年国务院办公厅春节放假通知:1月21日起休7天中评论 会不会春节放假后又阳一次?..BUG4 在
你翻墙过吗?国内使用vpn翻墙可能会被网警抓,你需了解的事中评论 不是吧?..博主 在
go语言+beego框架中获取get,post请求的所有参数中评论 @ t1 直接在router.go文件中配就ok..Jade 在
如何在MySQL查询中获得当月记录中评论 Dear zongscan.com team, We can skyroc..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号