---
title: "jquery 取值"
author: "zpball"
date: "2012-07-12T14:28:03Z"
tags: []
categories: ["Web前端"]
slug: "jquery"
draft: false
lastmod: "2012-07-12T14:28:03Z"
id: 1586543
url: "https://zpball.iteye.com/blog/1586543"
---

jquery radio取值，checkbox取值，select取值，radio选中，checkbox选中，select选中，及其相关 获取一组radio被选中项的值 var item = $('input\[@name=items]\[@checked]').val(); 获取select被选中项的文本 var item = $("select\[@name=items] option\[@selected]").text(); select下拉框的第二个元素为当前选中值 $('#select\_id')\[0].selectedIndex = 1; radio单选组的第二个元素为当前选中值 $('input\[@name=items]').get(1).checked = true; 获取值： 文本框，文本区域：$("#txt").attr("value")； 多选框checkbox：$("#checkbox\_id").attr("value")； 单选组radio： $("input\[@type=radio]\[@checked]").val(); 下拉框select： $('#sel').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的项目为当前选中项 $("11112222").appendTo("#sel")//添加下拉框的option $("#sel").empty()；//清空下拉框 jQuery 获取 radio 选中后的文字 首先，他给出的 HTML 示例如下： \[code="html"] 男 女 \[/code] jQuery 获取 radio 选中后的文本的方法，如下： $("input\[name='sex']:checked")\[0].nextSibling.nodeValue \[code="html"] 男 \[/code] 下获取时使用 next() 选择器，如下： $("input\[name='sex']:checked").next("span").text() \[code="html"] 男 女 \[/code] 获取 radio 选中后的文本 $("input\[name='sex']:checked").next("label").text()