当前第2页 返回上一页
(1)有时可能需要隐藏select,但是还得需要更改select所传递的值。(select的默认选中之为第一个,即下标为0的选项值)
1 2 3 4 5 6 | var gd2=document.getElementById( "goods_name2" );
if (gd2)
{
gd2[0].value=newvalue;
}
|
(2)原生js更改select选定的值
1 2 3 4 5 6 | var gd2=document.getElementById( "goods_name2" );
if (gd2)
{
gd2.value=newvalue;
}
|
1 2 3 | var obj = document.getElementById( "goods_name" );
var index = obj.selectedIndex;
obj.options[index].value=newvalue;
|
2、jquery设置select值的方法
1 2 | $( '#goods_name2 option:selected' ) .val(newvalue);
|
相关免费学习推荐:javascript视频教程
以上就是javascript如何设置select值的详细内容,更多文章请关注木庄网络博客!
返回前面的内容
相关阅读 >>
js如何修改html
es6中变量的解构赋值的用法介绍(附代码)
javascript怎么将负数转正
javascript有没有二维数组
javascript的内部方法有什么
javascript中哪种类型的循环最快?几种for循环对比
js对象基础知识的巩固学习笔记
javascript去除拼接字符串末尾符号的方法
清除浮动和闭合浮动的介绍
javascript可以放在css中吗
更多相关阅读请进入《javascript》频道 >>
人民邮电出版社
本书对 Vue.js 3 技术细节的分析非常可靠,对于需要深入理解 Vue.js 3 的用户会有很大的帮助。——尤雨溪,Vue.js作者
转载请注明出处:木庄网络博客 » javascript如何设置select值