Hi,大家好,我是编程小6,很荣幸遇见你,我把这些年在开发过程中遇到的问题或想法写出来,今天说一说js获取select的值,希望能够帮助你!!!。
var t = document.getElementById("provid");
console.log(t.value);
console.log(t.text); //未定义
console.log(t.selectedIndex); //有效
var text = t.options[t.selectedIndex].text; // 选中文本
var value = t.options[t.selectedIndex].value; // 选中值
console.log(text);
console.log(value);
var select_options = document.getElementById("typeid").options;
for (var i = 0; i < select_options.length; i++) {
if (select_options[i].value == type_id) {
select_options[i].selected = true;
break;
}
}
今天的分享到此就结束了,感谢您的阅读,如果确实帮到您,您可以动动手指转发给其他人。
上一篇
已是最后文章
下一篇
已是最新文章