Javascriptはselectを作成し、selectの値、テキストを取得する.radio、checkの値を取得します.
1283 ワード
// 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;
}