I'm new to coding and I need help with adding an onclick event to my list (which is supposed to work as a drop-down menu)-
This is the code for my list:
<div class="click-nav">
<ul class="clicker">
<ul>
<li><a href="#">shake</a></li>
<li><a href="#">shrink</a></li>
<li><a href="#">melt</a></li>
<li><a href="#">disperse</a></li>
</ul>
</ul>
</div>
I want to make it so that when one of these items is selected, a function is fired (which calls a bunch of images specific to the category selected to be placed in a div).
I've tried it also with the select option and it was working perfectly, but I have to change it because its stubborn design:
<label>
<select name="alphabets" id="typeface" onchange="myType();">
<option value="shake" selected>shake</option>
<option value="shrink">shrink</option>
<option value="melt">melt</option>
<option value="disperse">disperse</option>
<option value="disintegrate">disintegrate</option>
</select>
</label>
Thanks in advance for the help!
I'm new to coding and I need help with adding an onclick event to my list (which is supposed to work as a drop-down menu)-
This is the code for my list:
<div class="click-nav">
<ul class="clicker">
<ul>
<li><a href="#">shake</a></li>
<li><a href="#">shrink</a></li>
<li><a href="#">melt</a></li>
<li><a href="#">disperse</a></li>
</ul>
</ul>
</div>
I want to make it so that when one of these items is selected, a function is fired (which calls a bunch of images specific to the category selected to be placed in a div).
I've tried it also with the select option and it was working perfectly, but I have to change it because its stubborn design:
<label>
<select name="alphabets" id="typeface" onchange="myType();">
<option value="shake" selected>shake</option>
<option value="shrink">shrink</option>
<option value="melt">melt</option>
<option value="disperse">disperse</option>
<option value="disintegrate">disintegrate</option>
</select>
</label>
Thanks in advance for the help!
Share Improve this question asked Jul 29, 2013 at 22:53 circariemcircariem 111 gold badge1 silver badge3 bronze badges2 Answers
Reset to default 1You could just add onclick to each '' and call a different function for each one:
<script>
function shake(){
alert('Shake');
}
function shrink(){
alert('Shrink');
}
</script>
<div class="click-nav">
<ul class="clicker">
<ul>
<li><a href="#" onclick=shake();>shake</a></li>
<li><a href="#"onclick=shrink();>shrink</a></li>
<li><a href="#">melt</a></li>
<li><a href="#">disperse</a></li>
</ul>
</ul>
</div>
See this.
<html>
<div id="name">text</div>
<ul><li onclick="chaangeEvenet(this)">A </li><li onclick="chaangeEvenet(this)">B </li><li onclick="chaangeEvenet(this)">C </li></ul>
</html>
<script>
var namefield=document.getElementById("name");
function chaangeEvenet(e){
namefield.innerHTML=e.innerHTML;
}
</script>
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744214978a4563509.html
评论列表(0条)