1、原生js设置select选中值的方法
(1)有时可能需要隐藏select,但是还得需要更改select所传递的值。(select的默认选中之为第一个,即下标为0的选项值)
vargd2=document.getElementById("goods_name2");
//为防止有时指定id元素不存在导致的异常
if(gd2)
{
gd2[0].value=newvalue;
}
(2)原生js更改select选定的值
vargd2=document.getElementById("goods_name2");
//为防止有时指定id元素不存在导致的异常
if(gd2)
{
gd2.value=newvalue;//更改选定项,值为select选项中原有值(即换一个选择项)
}
varobj=document.getElementById("goods_name");//定位id
varindex=obj.selectedIndex;//选中索引
obj.options[index].value=newvalue;//更改选定项的原有值(产生了新的选择项)
2、jquery设置select选中值的方法
//设置select选定的值
$('#goods_name2option:selected').val(newvalue);
上一篇:CSS中auto有什么作用
下一篇:HTML常用标签有哪些