天天看点

javascript的select、radio、checkbox取值总结

(1)select取值value 跟获取<option>和</option>之间的文本

(0)逗比方法取值:只能取值 不能取<option>和</option>之间的文本

document.getElementById("nimei").value

$("#nimei").val()

(1)dom方法

document.getElementById("K_time");

var tt=t.options[t.selectedIndex].value;

取<option>和</option>之间的文本

var tt=t.options[t.selectedIndex].text;

(2)jq方法

var t=$("#K_time")[0];

var tt=t.options[t.selectedIndex].value;

注意:一定要加[0]  不加0会报错 

因为这是

不加【0】是jquery对象

加上就是dom对象

取<option>和</option>之间的文本

var tt=t.options[t.selectedIndex].text;

(2)radio跟checkbox的取值

(1)jquery取法

$("input[id='airuikun']:checked").val();

(2)dom取法:

    原理:因为选项很多 值很多 不是一个id 不能用get id

var c = document.getElementsByName("account");

            for(var i=0;i<c.length;i++)

             {

               if(c[i].checked){

                     alert(c[i].value);

  }

             }

继续阅读