最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

HTML javascript select action - Stack Overflow

programmeradmin9浏览0评论

I got a selection list:

<select>
<option value="0" onclick="anders('1')">Anders</option>
<option value="200" onclick="anders('');" selected="selected">&#8364; 200,-</option>
<option value="300" onclick="anders('')">&#8364; 300,-</option>
<option value="400" onclick="anders('')">&#8364; 400,-</option>
<option value="500" onclick="anders('')">&#8364; 500,-</option>
</select>

When I select value "0" something need to be visible, this is working in firefox but not in internet explorer. Even an alert function with onclick isn't working in IE, does anybody knows something for this?

I got a selection list:

<select>
<option value="0" onclick="anders('1')">Anders</option>
<option value="200" onclick="anders('');" selected="selected">&#8364; 200,-</option>
<option value="300" onclick="anders('')">&#8364; 300,-</option>
<option value="400" onclick="anders('')">&#8364; 400,-</option>
<option value="500" onclick="anders('')">&#8364; 500,-</option>
</select>

When I select value "0" something need to be visible, this is working in firefox but not in internet explorer. Even an alert function with onclick isn't working in IE, does anybody knows something for this?

Share Improve this question edited Jul 19, 2013 at 15:28 Taryn 248k57 gold badges370 silver badges408 bronze badges asked Feb 19, 2010 at 23:22 stefanstefan 531 gold badge2 silver badges4 bronze badges 1
  • Read your own question and pretend that's ALL the information you have. Now, could you help you? Including some of hte code may be helpful. – Erik Commented Feb 19, 2010 at 23:23
Add a comment  | 

1 Answer 1

Reset to default 11

You really should probably bind this logic to the onchange event of the select itself, and not the click event of the individual options:

var myDiv = document.getElementById("myDiv");
document.getElementById("mySelect").onchange = function(){
  myDiv.style.display = (this.selectedIndex == 0) ? "block" : "none";
}

When we bind it this way, we don't need to mix our HTML and our Javascript. Our HTML can look as simple as what follows:

<select id="mySelect" name="values">
  <option>0</option>
  <option>1</option>
  <option>2</option>
</select>
<div id="myDiv">
  <p>Select 0 to show me, otherwise I'm invisible!</p>
</div>

Online demo: http://jsbin.com/ijogi

发布评论

评论列表(0)

  1. 暂无评论