记个笔记(项目中遇到的关于input的一些操作)

1、批量获取inputvalue(通过遍历可以获取单个值):

$(".kw-type-ipt-arr input[type='text']").each(function () {
    console.log(this.value);
    word_praise.push(this.value);
});

2、获取input(单选/多选)选中的值:

a、多选:

  $('input[name="jin_dog"]:checked').each(function () {
       if(this.value){
             payType += this.value+",";
  }
  });

b、单选:

$(".step-2 input[name = 'sortmsg']:checked").val()

 

c、Select

$("#starthour option:selected").val();

 

3、判断input(单选/多选)是否选中:

$(".setintervaltime input[name = 'taskinterval']:checked").val();

 

 

4、js动态选中input(单选/多选):

a、单选:(遍历所有的单选值,如果值与设定值相等既选中)

$('.limit-age input:radio[name="limitage"]').each(function () {
    if(this.value == TaskInformation.limitAge){
        this.checked = "checked";
    }
});

 

b、多选:

$(".limit-age .limchoice")[0].checked = "checked";

 

c、下拉选择:

$("#starthour option").each(function () {
    if(this.value == TaskInformation.startRage){
        this.selected = true;
    }
});

 

原文地址:https://www.cnblogs.com/wxx-17-5-13/p/10024617.html