<select>与<option>使用总结
<select>标签常与<option>一起使用,<option>有标签属性selected,设置<option>的标签属性selected为selected,则该标签会显示被选中,但是在操作中选中别的某个<option>,并不会使其selected属性变为selected,所以在JS代码中获取被选中的
<option>标签比较麻烦,要有类似如下的代码的代码:
var options = $('#pageLength option'); for(var i = 0; i < options.length; i++) { if($(options[i]).prop('index') == $('#pageLength').prop('selectedIndex')) { pageLength = $(options[i]).attr('value'); } }
其中,selectedIndex是<select>标签的对象属性,其代表了被选中的<option>标签的索引,index是<option>标签的索引。
以上。
浙公网安备 33010602011771号