在html下拉框里让每个选项执行对应事件
js是:functionshow(index){if(index==1){document.getElementById("music").style.display="...
js是:
function show(index) {
if (index == 1) {
document.getElementById("music").style.display="block";
document.getElementById("videos").style.display="none";
}
else {
document.getElementById("music").style.display="none";
document.getElementById("vidoes").style.display="block";
}
}
html:
<label id="select" for="products" accesskey="o">Show Products </label>
<select id="products" name="products" tabindex="10" >
<option value=" " selected="selected" > </option>
<option value="All">All</option>
<option value="Music">Music</option>
<option value="Video">Videos</option>
</select>
怎样让点music的时候执行show(1);点videos的时候执行show(2); 展开
function show(index) {
if (index == 1) {
document.getElementById("music").style.display="block";
document.getElementById("videos").style.display="none";
}
else {
document.getElementById("music").style.display="none";
document.getElementById("vidoes").style.display="block";
}
}
html:
<label id="select" for="products" accesskey="o">Show Products </label>
<select id="products" name="products" tabindex="10" >
<option value=" " selected="selected" > </option>
<option value="All">All</option>
<option value="Music">Music</option>
<option value="Video">Videos</option>
</select>
怎样让点music的时候执行show(1);点videos的时候执行show(2); 展开
2个回答
展开全部
<select id="products" name="products" 绝裤旦tabindex="10" >
<option value=" " selected="selected" > </option>
<option value="All">All</option>
<option value="Music">Music</option>
<option value="Video">Videos</option>
</select>
//改为:
<select id="products" name="products" tabindex="10" onchange="show(this.value)">
<option value=" " selected="selected" > </option>
<option value="All">All</option>
<option value="1">Music</option>
<option value="2">Videos</option>
</select>
// onchange="show(this.value)" 三指当前元素改变时触发纯蚂
// 所以show(index) 中的参数值还有可能是all
所以把js部分改为
if (index == 1) {
document.getElementById("并扰music").style.display="block";
document.getElementById("videos").style.display="none";
}
else if(index == 2) {
document.getElementById("music").style.display="none";
document.getElementById("vidoes").style.display="block";
}
else{
document.getElementById("music").style.display="block";
document.getElementById("vidoes").style.display="block";
}
这应该是你想要的了
展开全部
<select id="products" name="products" tabindex="10" > <option value=" " selected="selected" > </option> 凳好裤 <option value="All">All</option> <option value="Music">Music</option> <option value="Video">Videos</option> </select>//改为:<select id="products" name="products" tabindex="10" onchange="show(this.value)"> 枣简 <option value=" " selected="selected" > </option> <option value="All">All</option> <option value="1">Music</option> <option value="2">Videos</option> </select>// onchange="show(this.value)" 三指当前元素改变时触发// 所以show(index) 中的参数值还有可能是all所以把js部分改为if (index == 1) { document.getElementById("music").style.display="block"; document.getElementById("videos").style.display="none"; } else if(index == 2) { document.getElementById("music").style.display="none"; document.getElementById("vidoes").style.display="block"; } else{document.getElementById("music").style.display="block"; document.getElementById("袜搭vidoes").style.display="block"; }
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询