学习掌握没有,就看你能不能说出“无非是...”。呵呵。 什么时候你琢磨透了,自己能用通俗的话说出来,就表明你掌握了(当然说错了不算)。
页面元素 select 操作 无非是 3点 。
options[x].value
options[x].text
options[x].selected=true
例子1
以下为html
<div class="span8 byProvider" style="min-height: 60px;">
<span>
<label>运营商</label>
<select class="serviceProviderId" name="serviceProviderId">
<option value="-1">All</option>
<option value="2">北京电信</option>
<option value="4">北京移动</option>
<option value="6">广东电信</option>
<option value="7">广东联通</option>
<option value="3">北京联通</option>
<option value="1">中国电信</option>
</select>
</span>
</div>
要设置select 值,用下面 javascript
var selectors=document.getElementsByClassName("serviceProviderId");
var selector= selectors[0];
for(var i=0;i<selector.length;i++){
console.log(selector.options[i]);
console.log(selector.options[i].text);
if(selector.options[i].value==4) selector.options[i].selected=true;
if(selector.options[i].text=="中国电信") selector.options[i].selected=true;
}
页面元素 select 操作 无非是 3点 。
options[x].value
options[x].text
options[x].selected=true
例子1
以下为html
<div class="span8 byProvider" style="min-height: 60px;">
<span>
<label>运营商</label>
<select class="serviceProviderId" name="serviceProviderId">
<option value="-1">All</option>
<option value="2">北京电信</option>
<option value="4">北京移动</option>
<option value="6">广东电信</option>
<option value="7">广东联通</option>
<option value="3">北京联通</option>
<option value="1">中国电信</option>
</select>
</span>
</div>
要设置select 值,用下面 javascript
var selectors=document.getElementsByClassName("serviceProviderId");
var selector= selectors[0];
for(var i=0;i<selector.length;i++){
console.log(selector.options[i]);
console.log(selector.options[i].text);
if(selector.options[i].value==4) selector.options[i].selected=true;
if(selector.options[i].text=="中国电信") selector.options[i].selected=true;
}