Home  >  Article  >  php教程  >  jQuery中的RadioButton,input,CheckBox取值赋值实现代码

jQuery中的RadioButton,input,CheckBox取值赋值实现代码

WBOY
WBOYOriginal
2016-06-13 09:30:31859browse

1、jquery 获取单选组radio
$("input[name='name']:checked").val();

2、jquery获取radiobutton的下一个值
$("input[name='name']:checked").next().text()
$("input[name='name']:checked").val()

3、jquery 获取input的值
$('#id').val()

4、jquery判断多选框checkbox
$("#id:checkbox").attr("checked")
取值 $("#id").attr("value");
赋值则是在text()、val()里面直接给值

JQUERY如何获取text,areatext,radio,checkbox,select值?
$("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) //判断是否已经打勾

单选组radio: $("input[@type=radio]").attr("checked",'2');//设置value=2的项目为当前选中项

下拉框select: $("#sel").attr("value",'-sel3');//设置value=-sel3的项目为当前选中项
$("").appendTo("#sel")//添加下拉框的option
$("#sel").empty();//清空下拉框

jQuery 获取和设置select下拉框的值文章分类:.net编程

获取Select :
获取select 选中的 text :
$("#ddlRegType").find("option:selected").text();

获取select选中的 value:
$("#ddlRegType ").val();

获取select选中的索引:
$("#ddlRegType ").get(0).selectedIndex;

设置select:
设置select 选中的索引:
$("#ddlRegType ").get(0).selectedIndex=index;//index为索引值

设置select 选中的value:
$("#ddlRegType ").attr("value","Normal“);
$("#ddlRegType ").val("Normal");
$("#ddlRegType ").get(0).value = value;

设置select 选中的text:
var count=$("#ddlRegType option").length;
for(var i=0;i{ if($("#ddlRegType ").get(0).options[i].text == text)
{
$("#ddlRegType ").get(0).options[i].selected = true;
break;
}
}
$("#select_id option[text='jQuery']").attr("selected", true);

设置select option项:
$("#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

清空 Select:
$("#ddlRegType ").empty();

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn