js 添加select option 和取值

xiaoxiao2026-09-21  1

function btnAdd_onclick()"{ var opt=new Option('New York','1'); document.fm.citys.options[0]=opt;}<form id="fm" name="fm">... <select name="citys" id="citys"> 删除select中的某一项option: document.getElementById("citys").options.remove(indx); 删除select中的所有options: document.getElementById("citys").options.length=0; 添加select中的项option: document.getElementById("citys").options.add(new Option(text,value)); 取值: function getvalue() { var obj = document.getElementById('citys'); var m=obj.options[obj.selectedIndex].value alert(m);//获取value var n=obj.options[obj.selectedIndex].text alert(n);//获取文本 } 相关资源:javascript 获取select ->option中id、value、label属性及<option></option>中内容
转载请注明原文地址: https://www.6miu.com/read-5052892.html

最新回复(0)