我有一个MenuBar,当前显示值为One,Two和Three。单击该菜单项(例如一个)我正在显示Label One
如何选择菜单项旁边的TickMark,并在取消选择时删除TickMark。
这是我的菜单条形码
<ul id="sddm" style="width:420px;margin:0 auto">
<li><a href="#" onmouseover="mopen('m1')" onmouseout="mclosetime()">Test</a>
<div id="m1" onmouseover="mcancelclosetime()" onmouseout="mclosetime()">
<a href="#" OnClick="MyFunction();">One</a>
<a href="#">Two</a>
<a href="#">Three</a>
</div>
</li>
这是我目前使用的样式表
#sddm
{ margin: 0;
padding: 0;
z-index: 30}
#sddm li
{ margin: 0;
padding: 0;
list-style: none;
float: left;
font: bold 11px arial}
#sddm li a
{ display: block;
margin: 0 1px 0 0;
padding: 4px 10px;
width: 60px;
background: #5970B2;
color: #FFF;
text-align: center;
text-decoration: none}
#sddm li a:hover
{ background: #49A3FF}
#sddm div
{ position: absolute;
visibility: hidden;
margin: 0;
padding: 0;
background: #EAEBD8;
border: 1px solid #5970B2}
#sddm div a
{ position: relative;
display: block;
margin: 0;
padding: 5px 10px;
width: auto;
white-space: nowrap;
text-align: left;
text-decoration: none;
background: #EAEBD8;
color: #2875DE;
font: 11px arial}
#sddm div a:hover
{ background: #49A3FF;
color: #FFF}
请帮忙
答案 0 :(得分:0)
类似的工作代码
<style>
#sddm li.ch{
background: url('remove.png') no-repeat;
}
</style>
<script src="jquery.js"></script>
<script>
$(function (){
$('#sddm li').click(function (){
if($(this).hasClass('ch')){
$(this).removeClass('ch');
}
else{
$(this).addClass('ch');
}
})
})
</script>
<ul id="sddm" style="width:420px;margin:0 auto">
<li><a href="#">Test 1</a></li>
<li><a href="#">Test 2</a></li>
<li><a href="#">Test 3</a></li>
</ul>
你的形象
答案 1 :(得分:0)
You have forcefully made the code accepted :) , Any help why this not displaying an Image beside the Menu Item
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(function (){
$('#sddm li').click(function (){
if($(this).hasClass('ch')){
$(this).removeClass('ch');
}
else{
$(this).addClass('ch');
}
})
})
</script>
</head>
<body>
<!-- body -->
<div id="center">
<!-- dd menu -->
<script type="text/javascript">
<!--
var timeout = 500;
var closetimer = 0;
var ddmenuitem = 0;
// open hidden layer
function mopen(id)
{
// cancel close timer
mcancelclosetime();
// close old layer
if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
// get new layer and show it
ddmenuitem = document.getElementById(id);
ddmenuitem.style.visibility = 'visible';
}
// close showed layer
function mclose()
{
if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
}
// go close timer
function mclosetime()
{
closetimer = window.setTimeout(mclose, timeout);
}
// cancel close timer
function mcancelclosetime()
{
if(closetimer)
{
window.clearTimeout(closetimer);
closetimer = null;
}
}
</script>
<style>
#sddm
{ margin: 0;
padding: 0;
z-index: 30}
#sddm li
{ margin: 0;
padding: 0;
list-style: none;
float: left;
font: bold 11px arial}
#sddm li a
{ display: block;
margin: 0 1px 0 0;
padding: 4px 10px;
width: 60px;
background: #5970B2;
color: #FFF;
text-align: center;
text-decoration: none}
#sddm li a:hover
{ background: #49A3FF}
#sddm div
{ position: absolute;
visibility: hidden;
margin: 0;
padding: 0;
background: #EAEBD8;
border: 1px solid #5970B2}
#sddm div a
{ position: relative;
display: block;
margin: 0;
padding: 5px 10px;
width: auto;
white-space: nowrap;
text-align: left;
text-decoration: none;
background: #EAEBD8;
color: #2875DE;
font: 11px arial}
#sddm div a:hover
{ background: #49A3FF;
color: #FFF}
#ch{
background: url('http://www.incorporate.net.au/incprod/images/tick_icon.gif') no-repeat;
}
</style>
<!-- div class="sample" style="margin-bottom: 15px;height:42px;"><span -->
<ul id="sddm" style="width:420px;margin:0 auto">
<li><a href="#" onmouseover="mopen('m1')" onmouseout="mclosetime()">Test</a>
<div id="m1" onmouseover="mcancelclosetime()" onmouseout="mclosetime()">
<a href="#" id="kii" >Hide All</a>
<a href="#" OnClick="MyFunction();" >Show All</a>
<a href="#" id="Oner" OnClick="MyFunction();" >One</a>
<a href="#" OnClick="MyFunction();" >Two</a>
</div>
</li>
</ul>
<div id="one" style="visibility:hidden" >
<LABEL FOR=user style="width:420px;margin:0 auto" ACCESSKEY=U>Google Search Bar :</LABEL>
<div>
<div id="two" style="visibility:hidden" >
<LABEL FOR=user style="width:420px;margin:0 auto" ACCESSKEY=U>Map Type control:</LABEL>
<div>
<div id="three" style="visibility:hidden" >
<LABEL FOR=user style="width:420px;margin:0 auto" ACCESSKEY=U>Zoom Control :</LABEL>
<div>
<div id="four" style="visibility:hidden" >
<LABEL FOR=user style="width:420px;margin:0 auto" ACCESSKEY=U>Latitude/Longitude Display:</LABEL>
<div>
</body>
</html>