关于select框的值

xiaoxiao2025-01-31  7

第一种写法:

//得到页面select对象 var objsel=document.getElementById("selobj"); //得到select对象的id值 var checkvalue=objsel.options[objsel.selectedIndex].value; //得到select对象的显示值 var str=objsel.options[objsel.selectedIndex].text;

 

第二种写法:

//得到页面select对象 var objsel= document.getElementById("selobj"); //得到select对象的id值 var str= objsel.options[objsel.options.selectedIndex].value; //得到select对象的显示值 var checkvalue= objsel.options[objsel.options.selectedIndex].innerHTML;

 

在开发中,可能还会遇到需要设置select标签框的初始值,以下代码可作参考:

function init(){ var objsel=document.getElementById("selobj"); var a = '<s:property value="#session.objView.TKnowledgetype.name" />'; for(var i=0;i<objsel.length;i++){ var b = objsel.options[i].text; if(a==b){ objsel.options[i].selected='selected'; return; } } }

 

转载请注明原文地址: https://www.6miu.com/read-5023638.html

最新回复(0)