Jquer获取页面控件的值 select,checkbox,radio

var CheckBoxs = new Array();

//alert($('input[@name=50067cdb-0e30-46fd-88e1-528f1e7070a1][@checked]').size());

//获取一组名为 50067cdb-0e30-46fd-88e1-528f1e7070a1 (CheckBox 选择框或 Radio)的 id ,title,value 的值
$('input[@name=50067cdb-0e30-46fd-88e1-528f1e7070a1][@checked]').each(function()
{
    //CheckBoxs.push($(this).val());
    var ss =$(this).attr("id")+'|'+$(this).attr("title")+'|'+$(this).val();
    CheckBoxs.push(ss);
})


//alert(CheckBoxs.toString());

//获取页面所有选择框的值 checkbox
var chs = new Array();
$("input[type=checkbox]:checked").each(function(){
chs.push($(this).val());
})
alert(chs.toString())

 

//获取页面textbox 不为空的值

var chsi = new Array();
$("input[type=text]").each(function(){
if($(this).val() !='')
chsi.push($(this).val());
})
alert(chsi.toString())

}


//$("input[type=text]").each //页面所有input控件的值
//$("input[type=checkbox]:checked").each //页面 所有 CheckBox 的 Value 值
//$("input[type=radio]:checked").each 页面 所有 radio 的 Value 值

 


获取一组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的项目为当前选中项
$("<option value='1'>1111</option><option value='2'>2222</option>").appendTo("#sel")//添加下拉框的option
$("#sel").empty();//清空下拉框

 

//获取CheckBoxList值,使用jQuery类库
function GetCheckBoxListValue(obj) { //obj为CheckBoxList的ClientID
     var v = new Array();
     $("#" + obj+ " input").each(function() {
         if (this.checked) {
             v.push($(this).parent().attr("alt"));
         }
     });
     return v; //返回一列以','分隔的结果
}


if( $("#obj input").length > 0)
       {
          if($("#obj  input:checked").length == 0)
          {
              alert("价格带 【"+document.getElementById("Label"+j.toString()+"").innerText+"】 尚未选择,请选择");
                    return false;
          }
 }

 

        //CheckBoxList 反选
        function CBLCheckALl(CheckBoxListName)
        {
            $("#" + CheckBoxListName + " input").each(function() {
            if (this.checked) {
               $(this).attr("checked",false);//
            }
            else
               $(this).attr("checked",true);
           });
        }

 

$("input[name='radio_name'][checked]").val(); //选择被选中Radio的Value值

$("#text_id").focus(function(){//code...}); //事件 当对象text_id获取焦点时触发

$("#text_id").blur(function(){//code...}); //事件 当对象text_id失去焦点时触发

$("#text_id").select(); //使文本框的Vlaue值成选中状态

$("input[name='radio_name'][value='要选中Radio的Value值'"). attr("checked",true);

//根据Value值设置Radio为选中状态
jQuery获取CheckBox选择的Value值

$("input[name='checkbox_name'][checked]"); //选择被选中CheckBox元素的集合 如果你想得到 Value值你需要遍历这个集合$($("input[name='checkbox_name'][checked]")).each(function(){arrChk+=this.value + ',';});//遍历被选中CheckBox元素的集合 得到Value值

$("#checkbox_id").attr("checked"); //获取一个CheckBox的状态(有没有被选中,返回true/false)

$("#checkbox_id").attr("checked",true); //设置一个CheckBox的状态为选中(checked=true)

$("#checkbox_id").attr("checked",false); //设置一个CheckBox的状态为不选中(checked=false)

$("input[name='checkbox_name']").attr("checked",$("#checkbox_id").attr("checked"));//根据3,4,5条,你可以分析分析这句代码的意思

$("#text_id").val().split(","); //将Text的Value值以','分隔 返回一个数组
上面的这些操作,其实就是jQuery选择器的使用,希望大家对jQuery选择器方面的知识要掌握扎实。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值