//创建一个select标签
var s = document.createElement("select") ;
var d = [{t:'one',v:'1'},{t:'two',v:'2'}] ;
for(var i in d){
var option = new Option(d[i].t,d[i].v);
s.options.add(option);
}
document.body.appendChild(s);
//获取标签的文本
function show()
{
var myselect = document.getElementById("select");
alert(myselect.selectedIndex);
alert(myselect.options[myselect.selectedIndex].text);
}
function show2(){
var myselect = document.getElementById("select");
for(var i=0;i<myselect.length ;i++){
if(myselect[i].selected == true){
alert(myselect[i].innerHTML);
}
}
}
//获取select的值
function getSelectedValue(name){
var obj=document.getElementById(name);
return obj.value;
}
//获取radio的选中的值
function getRadioValue(name){
var radioes = document.getElementsByName(name);
for(var i=0;i<radioes.length;i++)
{
if(radioes[i].checked){
return radioes[i].value;
}
}
return false;
}
Javascript创建select 以及获取select的值、文本;获取radio,check的值
点赞
收藏