我制作了一个按钮,在悬停时显示文字,但我想在用户点击按钮后显示文本,并在用户再次点击按钮后消失。代码基本上是一个按钮和文本,在设置为.80不透明度的黑框中显示“HELLO”。有什么建议吗?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- saved from url=(0016)about:internet -->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
td img {display: block;}body {
margin-left: 0px;
margin-top: 0px;
}
a:link {text-decoration: none;}
a:visited {text-decoration: none;}
a:visited {color:#0000FF;}
a:hover {text-decoration: underline;}
a:active {text-decoration: underline;}
body {
font: 16px/1.4 arial;
background-color: #7D8859;
}
body {
font: 16px/1.4 arial;
background-color: #7D8859;
}
.imgWrap {
position: absolute;
height: 76px;
width: 50px;
top: 556px;
}
.imgDescription {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(0, 0, 0, 0.80);
color: #fff;
margin: -500px -340px 85px 50px;
padding: 10px;
z-index:10;
visibility: hidden;
opacity: 0;
/*remove comment if you want a gradual transition between states
-webkit-transition: visibility opacity 0.2s;
*/
}
.imgWrap:hover .imgDescription {
visibility: visible;
opacity: 1;
}
</style>
<script src="../javascript/swfobject_modified.js" type="text/javascript"></script><script language="JavaScript1.2" type="text/javascript">
<!--
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_popupMsg(msg) { //v1.0
alert(msg);
}
//-->
</script>
<script language="javascript" src="../javascript/configure.js" type="text/javascript"></script>
<script language="javascript" src="../javascript/scorm.js" type="text/javascript"></script>
<script language="javascript" src="../javascript/lms.js" type="text/javascript"></script>
<script language="Javascript" src="../javascript/common.js" type="text/javascript"></script>
<script language="Javascript" src="../javascript/common2.js" type="text/javascript"></script>
<script type="text/javascript">
function popup(){
cuteLittleWindow = window.open("hey", "littleWindow", "location=no,width=320,height=200");
}
</script>
<link href="../css/style.css" rel="stylesheet" type="text/css" />
</head>
<body bgcolor="#ffffff" onload="MM_preloadImages('images/2-3_A.jpg','images/Module 3/3-0_A.jpg','images/Module 3/3-0_B.jpg','images/Module 3/3-0_E.jpg','images/Module 3/3-0_F.jpg','images/Module 3/3-2-1-7.jpg','images/Module 3/3-6-1a-5.jpg','images/Module 3/3-6-1a-2.jpg','images/Module 3/3-6-1a-1.jpg','images/module 4/4-2_A.jpg','interface/text_2.jpg')">
<table style="display: inline-table;" border="0" cellpadding="0" cellspacing="0" width="800" height="600">
<tr>
<td><table style="display: inline-table;" align=""left" border="0" cellpadding="0" cellspacing="0" width="800">
<tr> </tr>
</table>
</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td><table style="display: inline-table;" align=""left" border="0" cellpadding="0" cellspacing="0" width="800">
<tr>
<td><a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image10','','interface/text_2.jpg',1)">
<div class="imgWrap"><img src="interface/text_1.jpg" name="Image10" width="76" height="50" border="0" id="Image10" />
<p class="imgDescription">
HELLO!
</p>
</div></a><a href="m02_3.html" onmouseout="MM_swapImgRestore();" onmouseover="MM_swapImage('mircs_interface_r4_c15_s1','','../share/images/interface/mircs_interface_r4_c15_s2.jpg',1)"></a></td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>
答案 0 :(得分:2)
当我理解你的问题是正确的时,你需要一个按钮,当用户点击它时悬停是不同的?
你可以通过在按钮上添加一个类来处理点击的CSS。
$('button').on('click', function () {
$(this).addClass('clicked');
});
和css
button { background: red; }
button:hover { background: green; }
button.clicked { background: orange; }
button.clicked:hover { background: black; }
答案 1 :(得分:0)
使用innerText
和innerHTML
在检查代码时,您似乎使用了一些WISIWYG工具。
你问题上的标签只显示了javascript和html,css(你真正的工作环境),所以我假设这是用javascript和html,css。
以下是您可以复制和测试的代码段
<!doctype html>
<head>
<script>
function changeButtonText(el){
if (el.value == "HELLO")
el.value = "GOOD BYE";
else el.value="HELLO";
el = document.getElementById("concerned_ptag");
if (el.innerText == "HELLO")
el.innerText = "GOOD BYE";
else el.innerText="HELLO";
}
</script>
</head>
<body>
<p id="concerned_ptag">
HELLO
</p>
<input type="button" value ="HELLO" id="concerned_button" onclick="changeButtonText(this);">
</body>
</html>
为p标签设计样式对您来说更容易。否则,再次ping。
答案 2 :(得分:0)
当用户点击按钮时,会出现文字,再次点击时,会消失吗?
$(document).ready(function(){
$('.bt').click(function(){
$(this).find('span').fadeToggle();
});
});
<a class="bt"><span>Button Text</span></a>
检查小提琴是否有完整的CSS / HTML / jQuery: http://jsfiddle.net/y45nY/1/