用JS操作select的问题
在html中有个select <select name="spSize" onchange="toUrl()" id="spSize">
<option value="5">5条</option>
<option value="10">10条</option>
<option value="20">20条</option>
<option value="30">30条</option>
</select>
我使用JS操作select时可以用getElementById这种方法吗?我下面的这个方法写的有问题,要拿到select中所有options数量的大小的代码应该怎样编写?
function initPSize()
{
var spSize = document.getElementById("spSize");
alert(spSize); //我在alert的时候 出现一个null 这是怎么回事?
if(pNum.value == null)
{
pNum.value = 1;
}
for(var i = 0; i < spSize.options.length; i++)
{
if(spSize[i].value == '${pSize}')
{
spSize[i].selected="selected";
}
}
}