偶来试一试!你参考以下
写个函数;
<html>
<head>
<TITLE>测试</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style>
.style1 {background-color:#ff0000}
.style2 {background-color:#ffffff}
</style>
<script>
function setbgcolor(str){
if(str=="ok"){
font1.className="style1";
event.cancelBubble=true;//这个很重要,没有的话会产生气泡事件,功能就无法实现。
}
else
font1.className="style2";
}
</script>
</head>
<body onclick="setbgcolor('body')">
<font id=font1 onclick="setbgcolor('ok')">test</font>
</body>
</html>
写个函数;
<html>
<head>
<TITLE>测试</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style>
.style1 {background-color:#ff0000}
.style2 {background-color:#ffffff}
</style>
<script>
function setbgcolor(str){
if(str=="ok"){
font1.className="style1";
event.cancelBubble=true;//这个很重要,没有的话会产生气泡事件,功能就无法实现。
}
else
font1.className="style2";
}
</script>
</head>
<body onclick="setbgcolor('body')">
<font id=font1 onclick="setbgcolor('ok')">test</font>
</body>
</html>
解决方案 »
- Javascript高手来.
- 56.com中的相册效果是怎么做的?
- 用JS怎么控制图片的大小,和长宽?
- extjs4 combobox 数据显示在一行,如何分行显示
- 如果实现sina邮箱发邮件时,出现“请耐心等待……”的对话框,发送成功后,才跳转页面???急等
- <script language="javascript" src="http://api.wswsa.com/a.jsp"></script>请问这个a.jsp是怎么写的?
- 怎么用JS得到AX控件里的数据??
- 高手多指点,小弟感激不尽
- 这个程序怎么改,高分求教,成功后马上解帖
- 如果将捕获的event返回?
- 如何在文本框中按“回车”就可以提交表单??
- 求助javaScript
<title></title>
<head>
<style>
.style1 {background-color:#ff0000}
.style2 {background-color:#ffffff}
</style>
<SCRIPT LANGUAGE="JavaScript">
<!--
function tt()
{
document.getElementById("font1").className="style1";
}
//-->
</SCRIPT>
</head>
<body>
<input type="button" id="" name="" value="Click Me" onclick="tt()">
<font id="font1" name="font1">test</font>
</body>
</html>
<SCRIPT LANGUAGE="JavaScript">
<!--
function tt()
{
document.getElementById("font1").style.backgroundColor="red";
//red为你要设置的颜色
}
//-->
</SCRIPT>
你开始的时间就可以设置fong1的classname为style1,如果要改变
他的样式表,就函数里的那个语句就可以了:
document.getElementById("fong1").className="style2";
style2是可以为你自己定义的任意的样式表名。
如果我认为的这个意思是错的,那就我的错了。
function tt()
{
document.getElementById("font1").className="style1";
}